You are here

public function SystemManager::getAdminBlock in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 188
Contains \Drupal\system\SystemManager.

Class

SystemManager
System Manager Service.

Namespace

Drupal\system

Code

public function getAdminBlock(MenuLinkInterface $instance) {
  $content = array();

  // 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 = array(
    array(
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ),
    array(
      '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 $link \Drupal\Core\Menu\MenuLinkInterface */
    $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;
}