public function SystemManager::getAdminBlock in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/src/SystemManager.php \Drupal\system\SystemManager::getAdminBlock()
- 9 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.
File
- core/
modules/ system/ src/ SystemManager.php, line 182
Class
- SystemManager
- System Manager Service.
Namespace
Drupal\systemCode
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;
}