Issue #2466933 by andypost, smustgrave, xjm, effulgentsia: Change $info array argument to system_get_module_admin_tasks() to $name

merge-requests/4027/head
catch 2023-05-22 12:11:30 +01:00
parent 75085fa400
commit 42461a8717
5 changed files with 28 additions and 9 deletions

View File

@ -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) {

View File

@ -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');
}

View File

@ -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.

View File

@ -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,
];

View File

@ -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]));
}
}