Container not initialized in module_implements_alter()

Created on 10 November 2024, about 1 month ago

Problem/Motivation

I'm testing out the OOP hooks introduced in πŸ“Œ OOP hooks using attributes and event dispatcher Needs review and I ran into some trouble with the Field Encrypt module.

Field Encrypt is currently failing on next minor tests (pipeline and issue that created the pipeline πŸ“Œ Update GitLab CI config now that Drupal 11 is the default Active ).

The problem relates to hook_module_implements_alter().

Field Encrypt makes a call to \Drupal::state() in the hook (see the implementation). This has been working since 8.x, including 11.0, but is now broken on 11.1.x:

    Drupal\Tests\field_encrypt\Kernel\DynamicEntityHooksTest::testUnexpectedEntityTypeId
    Drupal\Core\DependencyInjection\ContainerNotInitializedException:
    \Drupal::$container is not initialized yet. \Drupal::setContainer() must be
    called with a real container.

I didn't see any mention of code updates related to hook_module_implements_alter() in the change record β†’ .

Steps to reproduce

See the pipeline described above.

πŸ› Bug report
Status

Active

Version

11.1 πŸ”₯

Component

base system

Created by

πŸ‡―πŸ‡΅Japan ptmkenny

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024