Chris@0: moduleHandler = $module_handler; Chris@0: $this->requestStack = $request_stack; Chris@0: $this->menuTree = $menu_tree; Chris@0: $this->menuActiveTrail = $menu_active_trail; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks for requirement severity. Chris@0: * Chris@0: * @return bool Chris@0: * Returns the status of the system. Chris@0: */ Chris@0: public function checkRequirements() { Chris@0: $requirements = $this->listRequirements(); Chris@0: return $this->getMaxSeverity($requirements) == static::REQUIREMENT_ERROR; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Displays the site status report. Can also be used as a pure check. Chris@0: * Chris@0: * @return array Chris@0: * An array of system requirements. Chris@0: */ Chris@0: public function listRequirements() { Chris@0: // Load .install files Chris@0: include_once DRUPAL_ROOT . '/core/includes/install.inc'; Chris@0: drupal_load_updates(); Chris@0: Chris@0: // Check run-time requirements and status information. Chris@0: $requirements = $this->moduleHandler->invokeAll('requirements', ['runtime']); Chris@0: uasort($requirements, function ($a, $b) { Chris@0: if (!isset($a['weight'])) { Chris@0: if (!isset($b['weight'])) { Chris@0: return strcasecmp($a['title'], $b['title']); Chris@0: } Chris@0: return -$b['weight']; Chris@0: } Chris@0: return isset($b['weight']) ? $a['weight'] - $b['weight'] : $a['weight']; Chris@0: }); Chris@0: Chris@0: return $requirements; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Extracts the highest severity from the requirements array. Chris@0: * Chris@0: * @param $requirements Chris@0: * An array of requirements, in the same format as is returned by Chris@0: * hook_requirements(). Chris@0: * Chris@0: * @return Chris@0: * The highest severity in the array. Chris@0: */ Chris@0: public function getMaxSeverity(&$requirements) { Chris@0: $severity = static::REQUIREMENT_OK; Chris@0: foreach ($requirements as $requirement) { Chris@0: if (isset($requirement['severity'])) { Chris@0: $severity = max($severity, $requirement['severity']); Chris@0: } Chris@0: } Chris@0: return $severity; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Loads the contents of a menu block. Chris@0: * Chris@0: * This function is often a destination for these blocks. Chris@0: * For example, 'admin/structure/types' needs to have a destination to be Chris@0: * valid in the Drupal menu system, but too much information there might be Chris@0: * hidden, so we supply the contents of the block. Chris@0: * Chris@0: * @return array Chris@16: * A render array suitable for Chris@16: * \Drupal\Core\Render\RendererInterface::render(). Chris@0: */ Chris@0: public function getBlockContents() { Chris@0: // We hard-code the menu name here since otherwise a link in the tools menu Chris@0: // or elsewhere could give us a blank block. Chris@0: $link = $this->menuActiveTrail->getActiveLink('admin'); Chris@0: if ($link && $content = $this->getAdminBlock($link)) { Chris@0: $output = [ Chris@0: '#theme' => 'admin_block_content', Chris@0: '#content' => $content, Chris@0: ]; Chris@0: } Chris@0: else { Chris@0: $output = [ Chris@0: '#markup' => t('You do not have any administrative items.'), Chris@0: ]; Chris@0: } Chris@0: return $output; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Provide a single block on the administration overview page. Chris@0: * Chris@0: * @param \Drupal\Core\Menu\MenuLinkInterface $instance Chris@0: * The menu item to be displayed. Chris@0: * Chris@0: * @return array Chris@0: * An array of menu items, as expected by admin-block-content.html.twig. Chris@0: */ Chris@0: public function getAdminBlock(MenuLinkInterface $instance) { Chris@0: $content = []; Chris@0: // Only find the children of this link. Chris@0: $link_id = $instance->getPluginId(); Chris@0: $parameters = new MenuTreeParameters(); Chris@0: $parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks(); Chris@0: $tree = $this->menuTree->load(NULL, $parameters); Chris@0: $manipulators = [ Chris@0: ['callable' => 'menu.default_tree_manipulators:checkAccess'], Chris@0: ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'], Chris@0: ]; Chris@0: $tree = $this->menuTree->transform($tree, $manipulators); Chris@0: foreach ($tree as $key => $element) { Chris@0: // Only render accessible links. Chris@0: if (!$element->access->isAllowed()) { Chris@0: // @todo Bubble cacheability metadata of both accessible and Chris@0: // inaccessible links. Currently made impossible by the way admin Chris@0: // blocks are rendered. Chris@0: continue; Chris@0: } Chris@0: Chris@0: /** @var $link \Drupal\Core\Menu\MenuLinkInterface */ Chris@0: $link = $element->link; Chris@0: $content[$key]['title'] = $link->getTitle(); Chris@0: $content[$key]['options'] = $link->getOptions(); Chris@0: $content[$key]['description'] = $link->getDescription(); Chris@0: $content[$key]['url'] = $link->getUrlObject(); Chris@0: } Chris@0: ksort($content); Chris@0: return $content; Chris@0: } Chris@0: Chris@0: }