You are here

function system_get_module_admin_tasks in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/system.module \system_get_module_admin_tasks()
  2. 5 modules/system/system.module \system_get_module_admin_tasks()
  3. 6 modules/system/system.module \system_get_module_admin_tasks()
  4. 7 modules/system/system.module \system_get_module_admin_tasks()
  5. 9 core/modules/system/system.module \system_get_module_admin_tasks()

Generate a list of tasks offered by a specified module.

Parameters

string $module: Module name.

array $info: The module's information, as provided by \Drupal::service('extension.list.module')->getExtensionInfo().

Return value

array An array of task links.

3 calls to system_get_module_admin_tasks()
AdminController::index in core/modules/system/src/Controller/AdminController.php
Prints a listing of admin tasks, organized by module.
HelpController::helpPage in core/modules/help/src/Controller/HelpController.php
Prints a page listing general help for a module.
HelpTest::verifyHelp in core/modules/help/tests/src/Functional/HelpTest.php
Verifies the logged in user has access to the various help pages.

File

core/modules/system/system.module, line 982
Configuration system that lets administrators modify the workings of the site.

Code

function system_get_module_admin_tasks($module, array $info) {
  $tree =& drupal_static(__FUNCTION__);
  $menu_tree = \Drupal::menuTree();
  if (!isset($tree)) {
    $parameters = new MenuTreeParameters();
    $parameters
      ->setRoot('system.admin')
      ->excludeRoot()
      ->onlyEnabledLinks();
    $tree = $menu_tree
      ->load('system.admin', $parameters);
    $manipulators = [
      [
        'callable' => 'menu.default_tree_manipulators:checkAccess',
      ],
      [
        'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
      ],
      [
        'callable' => 'menu.default_tree_manipulators:flatten',
      ],
    ];
    $tree = $menu_tree
      ->transform($tree, $manipulators);
  }
  $admin_tasks = [];
  foreach ($tree as $element) {
    if (!$element->access
      ->isAllowed()) {

      // @todo Bubble cacheability metadata of both accessible and inaccessible
      //   links. Currently made impossible by the way admin tasks are rendered.
      continue;
    }
    $link = $element->link;
    if ($link
      ->getProvider() != $module) {
      continue;
    }
    $admin_tasks[] = [
      'title' => $link
        ->getTitle(),
      'description' => $link
        ->getDescription(),
      'url' => $link
        ->getUrlObject(),
    ];
  }

  // Append link for permissions.

  /** @var \Drupal\user\PermissionHandlerInterface $permission_handler */
  $permission_handler = \Drupal::service('user.permissions');
  if ($permission_handler
    ->moduleProvidesPermissions($module)) {

    /** @var \Drupal\Core\Access\AccessManagerInterface $access_manager */
    $access_manager = \Drupal::service('access_manager');
    if ($access_manager
      ->checkNamedRoute('user.admin_permissions.module', [
      'modules' => $module,
    ], \Drupal::currentUser())) {

      /** @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'],
        ]),
        'description' => '',
        'url' => $url,
      ];
    }
  }
  return $admin_tasks;
}