Problem/Motivation
Having two hooks:
Module A:
a_form_node_form_alter
Module B:
b_form_alter
a_form_node_form_alter will be called before b_form_alter.
But according to the documentation from the form api the behavior should be different without exceptions:
* Form alter hooks are called in the following order: hook_form_alter(),
* hook_form_BASE_FORM_ID_alter(), hook_form_FORM_ID_alter()
But it looks like that the order is per module instead global. If this is the desired behavior then we should document it.
Proposed resolution
This is the desired behavior, but it was documented only on the hook_form_alter, so we have to update the documentation of hook_form_FORM_ID_alter and hook_form_BASE_FORM_ID_alter.
Remaining tasks
Review & Commit.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#10 | 2842141-10.patch | 2.27 KB | hchonov |
Comments
Comment #2
hchonovComment #3
hchonovAssigning to the "base system" as the problem is \Drupal\Core\Extension\ModuleHandler::alter.
Comment #4
hchonovComment #5
hchonov@berdir just told me in IRC that this is the desired behavior referring to #765860: drupal_alter() fails to order modules correctly in some cases. So I guess we only have to write a better documentation for the form alter hooks?
Comment #6
cilefen CreditAttribution: cilefen commentedIt seems like you would implement hook_module_implements_alter if I understand the use-case.
Comment #7
hchonovNo, I am not implementing hook_module_implements_alter, but even if I do it would not help.
Comment #8
cilefen CreditAttribution: cilefen commentedOh, I see #5 came in just before I commented.
Comment #9
hchonovComment #10
hchonovActually hook_form_alter has the correct documentation, only hook_form_FORM_ID_alter and hook_form_BASE_FORM_ID_alter have to be updated.
Comment #22
borisson_The documentation is now in line with the documentation on hook_form_alter, so I think this makes sense
Comment #23
alexpottNice find. I checked the documentation of \Drupal\Core\Extension\ModuleHandlerInterface::alter() too and that also agrees with this change.
Committed and pushed 9aade7f4da to 10.1.x and edd591e678 to 10.0.x and 4924eccd53 to 9.5.x and 1857fea102 to 9.4.x. Thanks!
Backporting this docs fix to 9.4.x.