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.

CommentFileSizeAuthor
#10 2842141-10.patch2.27 KBhchonov
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hchonov created an issue. See original summary.

hchonov’s picture

Issue summary: View changes
hchonov’s picture

Assigning to the "base system" as the problem is \Drupal\Core\Extension\ModuleHandler::alter.

hchonov’s picture

Issue summary: View changes
hchonov’s picture

@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?

cilefen’s picture

It seems like you would implement hook_module_implements_alter if I understand the use-case.

hchonov’s picture

No, I am not implementing hook_module_implements_alter, but even if I do it would not help.

cilefen’s picture

Oh, I see #5 came in just before I commented.

hchonov’s picture

Title: A more specific hooks are called before the primary hook depending on the module names » Document that more specific hooks might be called before the primary hook depending on the module names
hchonov’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
2.27 KB

Actually hook_form_alter has the correct documentation, only hook_form_FORM_ID_alter and hook_form_BASE_FORM_ID_alter have to be updated.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Bug Smash Initiative

The documentation is now in line with the documentation on hook_form_alter, so I think this makes sense

alexpott’s picture

Version: 9.5.x-dev » 9.4.x-dev
Status: Reviewed & tested by the community » Fixed

Nice 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.

  • alexpott committed 9aade7f on 10.1.x
    Issue #2842141 by hchonov: Document that more specific hooks might be...

  • alexpott committed edd591e on 10.0.x
    Issue #2842141 by hchonov: Document that more specific hooks might be...

  • alexpott committed 4924ecc on 9.5.x
    Issue #2842141 by hchonov: Document that more specific hooks might be...

  • alexpott committed 1857fea on 9.4.x
    Issue #2842141 by hchonov: Document that more specific hooks might be...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.