You are here

function system_get_module_admin_tasks in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 system_get_info().

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/src/Tests/HelpTest.php
Verifies the logged in user has access to the various help nodes.

File

core/modules/system/system.module, line 1190
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 = array(
      array(
        'callable' => 'menu.default_tree_manipulators:checkAccess',
      ),
      array(
        'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
      ),
      array(
        'callable' => 'menu.default_tree_manipulators:flatten',
      ),
    );
    $tree = $menu_tree
      ->transform($tree, $manipulators);
  }
  $admin_tasks = array();
  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[] = array(
      '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', array(), \Drupal::currentUser())) {

      /** @var \Drupal\Core\Url $url */
      $url = new \Drupal\Core\Url('user.admin_permissions');
      $url
        ->setOption('fragment', 'module-' . $module);
      $admin_tasks["user.admin_permissions.{$module}"] = array(
        'title' => t('Configure @module permissions', array(
          '@module' => $info['name'],
        )),
        'description' => '',
        'url' => $url,
      );
    }
  }
  return $admin_tasks;
}