function SystemManager::getAdminBlock

Same name in other branches
  1. 9 core/modules/system/src/SystemManager.php \Drupal\system\SystemManager::getAdminBlock()
  2. 8.9.x core/modules/system/src/SystemManager.php \Drupal\system\SystemManager::getAdminBlock()
  3. 10 core/modules/system/src/SystemManager.php \Drupal\system\SystemManager::getAdminBlock()

Provide a single block on the administration overview page.

Parameters

\Drupal\Core\Menu\MenuLinkInterface $instance: The menu item to be displayed.

Return value

array An array of menu items, as expected by admin-block-content.html.twig.

1 call to SystemManager::getAdminBlock()
SystemManager::getBlockContents in core/modules/system/src/SystemManager.php
Loads the contents of a menu block.

File

core/modules/system/src/SystemManager.php, line 183

Class

SystemManager
System Manager Service.

Namespace

Drupal\system

Code

public function getAdminBlock(MenuLinkInterface $instance) {
    $content = [];
    // Only find the children of this link.
    $link_id = $instance->getPluginId();
    $parameters = new MenuTreeParameters();
    $parameters->setRoot($link_id)
        ->excludeRoot()
        ->setTopLevelOnly()
        ->onlyEnabledLinks();
    $tree = $this->menuTree
        ->load(NULL, $parameters);
    $manipulators = [
        [
            'callable' => 'menu.default_tree_manipulators:checkAccess',
        ],
        [
            'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
        ],
    ];
    $tree = $this->menuTree
        ->transform($tree, $manipulators);
    foreach ($tree as $key => $element) {
        // Only render accessible links.
        if (!$element->access
            ->isAllowed()) {
            // @todo Bubble cacheability metadata of both accessible and
            //   inaccessible links. Currently made impossible by the way admin
            //   blocks are rendered.
            continue;
        }
        
        /** @var \Drupal\Core\Menu\MenuLinkInterface $link */
        $link = $element->link;
        $content[$key]['title'] = $link->getTitle();
        $content[$key]['options'] = $link->getOptions();
        $content[$key]['description'] = $link->getDescription();
        $content[$key]['url'] = $link->getUrlObject();
    }
    ksort($content);
    return $content;
}

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