From 42461a871786caceef43635f085bc4eb8f24ea99 Mon Sep 17 00:00:00 2001 From: catch Date: Mon, 22 May 2023 12:11:30 +0100 Subject: [PATCH] Issue #2466933 by andypost, smustgrave, xjm, effulgentsia: Change $info array argument to system_get_module_admin_tasks() to $name --- .../help/src/Controller/HelpController.php | 2 +- .../help/tests/src/Functional/HelpTest.php | 5 +++-- .../system/src/Controller/AdminController.php | 2 +- core/modules/system/system.module | 16 +++++++++++----- .../Kernel/System/SystemFunctionsLegacyTest.php | 12 ++++++++++++ 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/core/modules/help/src/Controller/HelpController.php b/core/modules/help/src/Controller/HelpController.php index a19f6bf9f1b..6efdcc72dda 100644 --- a/core/modules/help/src/Controller/HelpController.php +++ b/core/modules/help/src/Controller/HelpController.php @@ -150,7 +150,7 @@ class HelpController extends ControllerBase { // Only print list of administration pages if the module in question has // any such pages associated with it. - $admin_tasks = system_get_module_admin_tasks($name, $info); + $admin_tasks = system_get_module_admin_tasks($name, $info['name']); if (!empty($admin_tasks)) { $links = []; foreach ($admin_tasks as $task) { diff --git a/core/modules/help/tests/src/Functional/HelpTest.php b/core/modules/help/tests/src/Functional/HelpTest.php index 79b25d62bd5..5115dcd3640 100644 --- a/core/modules/help/tests/src/Functional/HelpTest.php +++ b/core/modules/help/tests/src/Functional/HelpTest.php @@ -129,6 +129,7 @@ class HelpTest extends BrowserTestBase { $this->assertSession()->pageTextNotContains('This page shows you all available administration tasks for each module.'); } + $module_list = \Drupal::service('extension.list.module'); foreach ($this->getModuleList() as $module => $name) { // View module help page. $this->drupalGet('admin/help/' . $module); @@ -136,8 +137,8 @@ class HelpTest extends BrowserTestBase { if ($response == 200) { $this->assertSession()->titleEquals("$name | Drupal"); $this->assertEquals($name, $this->cssSelect('h1.page-title')[0]->getText(), "$module heading was displayed"); - $info = \Drupal::service('extension.list.module')->getExtensionInfo($module); - $admin_tasks = system_get_module_admin_tasks($module, $info); + $info = $module_list->getExtensionInfo($module); + $admin_tasks = system_get_module_admin_tasks($module, $info['name']); if (!empty($admin_tasks)) { $this->assertSession()->pageTextContains($name . ' administration pages'); } diff --git a/core/modules/system/src/Controller/AdminController.php b/core/modules/system/src/Controller/AdminController.php index 3af437623bd..843b544d776 100644 --- a/core/modules/system/src/Controller/AdminController.php +++ b/core/modules/system/src/Controller/AdminController.php @@ -51,7 +51,7 @@ class AdminController extends ControllerBase { foreach ($extensions as $module => $extension) { // Only display a section if there are any available tasks. - if ($admin_tasks = system_get_module_admin_tasks($module, $extension->info)) { + if ($admin_tasks = system_get_module_admin_tasks($module, $extension->info['name'])) { // Sort links by title. uasort($admin_tasks, ['\Drupal\Component\Utility\SortArray', 'sortByTitleElement']); // Move 'Configure permissions' links to the bottom of each section. diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 65b85da0c70..9a0926a9a92 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -973,14 +973,20 @@ function system_admin_compact_mode() { * * @param string $module * Module name. - * @param array $info - * The module's information, as provided by - * \Drupal::service('extension.list.module')->getExtensionInfo(). + * @param string|array $module_name + * The module's display name. Passing information, as provided by + * \Drupal::service('extension.list.module')->getExtensionInfo() is + * deprecated in drupal:10.2.0. Pass only $info["name"] instead. * * @return array * An array of task links. */ -function system_get_module_admin_tasks($module, array $info) { +function system_get_module_admin_tasks($module, string|array $module_name) { + if (!is_string($module_name)) { + @trigger_error('Calling ' . __FUNCTION__ . '() with $module_name argument as array is deprecated in drupal:10.2.0 and is required to be string from drupal:11.0.0. Pass only $info["name"] instead. See https://www.drupal.org/node/3357711', E_USER_DEPRECATED); + $module_name = $module_name['name']; + } + $tree = &drupal_static(__FUNCTION__); $menu_tree = \Drupal::menuTree(); @@ -1027,7 +1033,7 @@ function system_get_module_admin_tasks($module, array $info) { /** @var \Drupal\Core\Url $url */ $url = new Url('user.admin_permissions.module', ['modules' => $module]); $admin_tasks["user.admin_permissions.$module"] = [ - 'title' => t('Configure @module permissions', ['@module' => $info['name']]), + 'title' => t('Configure @module permissions', ['@module' => $module_name]), 'description' => '', 'url' => $url, ]; diff --git a/core/modules/system/tests/src/Kernel/System/SystemFunctionsLegacyTest.php b/core/modules/system/tests/src/Kernel/System/SystemFunctionsLegacyTest.php index 1d26bd50f40..e3fd9947bc0 100644 --- a/core/modules/system/tests/src/Kernel/System/SystemFunctionsLegacyTest.php +++ b/core/modules/system/tests/src/Kernel/System/SystemFunctionsLegacyTest.php @@ -17,6 +17,8 @@ class SystemFunctionsLegacyTest extends KernelTestBase { */ protected static $modules = [ 'system', + // Test system_get_module_admin_tasks() require user.permissions service. + 'user', ]; /** @@ -27,4 +29,14 @@ class SystemFunctionsLegacyTest extends KernelTestBase { system_time_zones(); } + /** + * @covers ::system_get_module_admin_tasks + */ + public function testSystemGetModuleAdminTasksArgument() { + $module_name = 'System'; + $expected = system_get_module_admin_tasks('system', $module_name); + $this->expectDeprecation('Calling system_get_module_admin_tasks() with $module_name argument as array is deprecated in drupal:10.2.0 and is required to be staring from drupal:11.0.0. Pass only $info["name"] instead. See https://www.drupal.org/node/3357711'); + $this->assertSame($expected, system_get_module_admin_tasks('system', ['name' => $module_name])); + } + }