Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Current the webform submission form includes the source entity type and id in the form ID.
hook_form_{BASE_FORM_ID}_{WEBFORM_ID}_{ENTITY_TYPE}_{ENTITY_ID}_{OPERATION}_form_alter()
Most form alteration should target just the webform id and operation.
hook_form_{BASE_FORM_ID}_{WEBFORM_ID}_{OPERATION}_form_alter()
Maybe we should remove the source entity type and id from the form id.
Proposed resolution
Remove source entity from webform submission form ids
Remaining tasks
- Remove source entity from form id
- Fix broken tests
- Write change record
User interface changes
TDB
API changes
TDB
Data model changes
TDB
Comment | File | Size | Author |
---|---|---|---|
#8 | 2949523-form-id-8.patch | 5.3 KB | jrockowitz |
| |||
#8 | interdiff-2949523-7-8.txt | 1.92 KB | jrockowitz |
#7 | 2949523-form-id-7.patch | 3.28 KB | bucefal91 |
| |||
#7 | interdiff-6-7.txt | 1.37 KB | bucefal91 |
#6 | 2949523-6.patch | 2.37 KB | jrockowitz |
|
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #4
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #6
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #7
bucefal91 CreditAttribution: bucefal91 at Websolutions Agency commentedhello, Jacob! :)
Yes, that looks fine to me. I do not have much to suggest. The only thing I see is the new
WebformSubmissionForm::getFormId()
looks just as its parent. So we can remove the method as a whole and use parent's implementation of that method. Hehe, you can tell I really like removing code :)Just out of curiosity I glanced into
webform_form_webform_submission_form_alter()
and there are some findings.It seems that you're running another set of form_alters in there:
Notice, that
webform_form_webform_submission_form_alter()
has an IF statement to add one more hook if the current webform has source entity. Maybe you want to remove that part too?Lastly, I attach the patch that removes
::getFormId()
.Comment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@bucefal91 Does this change make sense? Is including the source entity in the webforms id making it too specific?
This change is going to break some people code but simplify the webform module's form alter hooks.
Comment #9
bucefal91 CreditAttribution: bucefal91 at Websolutions Agency commentedYep, it sounds reasonable to me. I do not expect many people would care for the source entity. And those (hopefully few) who do care, still can include necessary IF statements inside of their implementation of
hook_form_webform_submission_WEBFORM_ID_form_alter()
.I think with the patch committed there is still plenty machinery to alter the form for custom module developers.
Comment #11
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #12
BerdirFYI: One thing this broke for us is a captcha configuration for the old form_id. I know that this can be added directly in webform and I asume most people are doing it like that, and it actually only was there for historical reasons in the default config of our distribution (originally we used contact.module, had an captcha example form for it, that was then migrated to webform at some point but we kept the configuration in captcha).
Comment #13
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@Berdir If you have to write a custom update hook to fix the regression with CAPTCHA module. Please create a new ticket with the code snippet. I would be open to adding it the webform module's update hooks.
Comment #14
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedNow this change has caused this regression #2957002: Same webform multiple times on the same page. This patch might have to be reverted.
Comment #16
kmajzlik CreditAttribution: kmajzlik at Ciklum Western Europe for BurdaForward commentedPlease re-open this. It is not fixed after commit revert. There is no easy solution to add Captcha now if you have webform shown on all nodes of certain type for example.
Probably there can be some setting on Webform entity.
Or maybe do something with getBaseFormId() ?
Comment #17
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedPlease create a new ticket. I do want to note that we can't make any changes to any form ids because it would break everyone's current form alter hooks.