From e8206cbd374c8963b4339cbc67fb20e0e032aeab Mon Sep 17 00:00:00 2001 From: catch <6915-catch@users.noreply.drupalcode.org> Date: Thu, 23 Jan 2025 11:50:27 +0000 Subject: [PATCH] Issue #2233261 by nicxvan, catch, berdir, andypost, sun: Deprecate hook_hook_info groups, mark hook_hook_info() for deletion --- .../Drupal/Core/Extension/ModuleHandler.php | 1 + core/lib/Drupal/Core/Extension/module.api.php | 20 +++++++++---------- .../Core/Extension/ModuleHandlerTest.php | 3 +++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index 5acd758c9297..cf42c65deeff 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 03d78ca9617e..8806c706e805 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 0644f1db5d21..500973836ede 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'); -- GitLab