diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index 5acd758c9297d99e9e37c7b87068afcdeee56c14..cf42c65deeff28e02426e1517c203e3b91b998f3 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -567,6 +567,7 @@ protected function getHookListeners(string $hook): array { } if (isset($this->groupIncludes[$hook])) { foreach ($this->groupIncludes[$hook] as $include) { + @trigger_error('Autoloading hooks in the file (' . $include . ') is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Move the functions in this file to either the .module file or other appropriate location. See https://www.drupal.org/node/3489765', E_USER_DEPRECATED); include_once $include; } } diff --git a/core/lib/Drupal/Core/Extension/module.api.php b/core/lib/Drupal/Core/Extension/module.api.php index 03d78ca9617e24c569bb0d37e1e6013d8b4975e8..8806c706e805139db2fc9b82efb3afff9490e379 100644 --- a/core/lib/Drupal/Core/Extension/module.api.php +++ b/core/lib/Drupal/Core/Extension/module.api.php @@ -64,17 +64,15 @@ * * Only procedural implementations are supported for this hook. * - * Normally hooks do not need to be explicitly defined. However, by declaring a - * hook explicitly, a module may define a "group" for it. Modules that implement - * a hook may then place their implementation in either $module.module or in - * $module.$group.inc. If the hook is located in $module.$group.inc, then that - * file will be automatically loaded when needed. - * In general, hooks that are rarely invoked and/or are very large should be - * placed in a separate include file, while hooks that are very short or very - * frequently called should be left in the main module file so that they are - * always available. - * - * See system_hook_info() for all hook groups defined by Drupal core. + * Support for this hook will be removed in Drupal 12.0.0. + * This hook has intentionally not been deprecated since removing + * implementations will break modules with code in $module.$group.inc files. + * + * $module.$group.inc themselves have been deprecated, so modules supporting + * drupal 12.0.0 will have removed all code from $module.$group.inc files. + * + * Once a module requires 12.0.0 as a minimum version of Drupal the module can + * safely remove hook_hook_info() implementations. * * @return array * An associative array whose keys are hook names and whose values are an diff --git a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php index 0644f1db5d213484357fc816ba9c27ffc8f0ea85..500973836edec61d069c9b83d7eda0ae4d5e7740 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php @@ -384,9 +384,12 @@ public function testGetModuleDirectories(): void { /** * @covers ::getHookListeners + * + * @group legacy */ public function testGroupIncludes(): void { self::setupGroupIncludes(); + $this->expectDeprecation('Autoloading hooks in the file (vfs://drupal_root/test_module.tokens.inc) is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Move the functions in this file to either the .module file or other appropriate location. See https://www.drupal.org/node/3489765'); $moduleHandler = new ModuleHandler('', [], new EventDispatcher(), [], self::GROUP_INCLUDES); $this->assertFalse(function_exists('_test_module_helper')); $moduleHandler->invokeAll('token_info');