function system_get_module_admin_tasks

Same name in other branches
  1. 7.x modules/system/system.module \system_get_module_admin_tasks()
  2. 9 core/modules/system/system.module \system_get_module_admin_tasks()
  3. 10 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 1142

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.