Problem/Motivation
Installing a site from a recipe that installs Big Menu fails:
InvalidArgumentException: Class "bigmenu_entity_type_alter" does not exist.
While the installer installs a module, ModuleInstaller::doInstall() rebuilds the container before it loads the module's .module file. When something builds the entity type definitions during that rebuild, ModuleHandler::alter() resolves bigmenu_entity_type_alter before the function exists, and the callable resolver treats the name as a class.
Applying the same recipe to an installed site works, because there the .module file is already loaded.
Steps to reproduce
Seen with Drupal 11.4.7 and 11.4.8 and Big Menu 2.1.0:
- Create a recipe that installs
bigmenutogether with a module whose code builds entity type definitions while the container is rebuilt. In our case it is a language negotiation plugin that callshasPermission(). - Run
drush site:install path/to/recipe.
Proposed resolution
Implement the hook as an OOP hook, Drupal\bigmenu\Hook\BigmenuHooks::entityTypeAlter() with #[Hook('entity_type_alter')]. The class is autoloaded, so the hook resolves during the rebuild. The procedural function stays as a #[LegacyHook] shim that calls the class, and bigmenu.services.yml registers the class so cores before 11.1 can reach it.
With the change, the recipe installs and the menu edit form is Drupal\bigmenu\BigMenuForm.
Remaining tasks
Review.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork bigmenu-3629643
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
lussolucaComment #4
acbramley commentedThank you for the report, since this is a subset of the changes in #3595844: Automated Drupal 12 compatibility fixes for bigmenu 2.x-dev I will merge that one instead. I've given you credit for this issue :)