diff --git a/core/modules/system/lib/Drupal/system/SystemManager.php b/core/modules/system/lib/Drupal/system/SystemManager.php index 86712a7..c29241c 100644 --- a/core/modules/system/lib/Drupal/system/SystemManager.php +++ b/core/modules/system/lib/Drupal/system/SystemManager.php @@ -6,6 +6,8 @@ namespace Drupal\system; +use Drupal\Component\Utility\Unicode; +use Drupal\Core\Entity\EntityManager; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -30,6 +32,20 @@ class SystemManager { protected $database; /** + * The menu link storage. + * + * @var \Drupal\menu_link\MenuLinkStorageControllerInterface + */ + protected $menuLinkStorage; + + /** + * A static cache of menu items. + * + * @var array + */ + protected $menuItems; + + /** * Requirement severity -- Requirement successfully met. */ const REQUIREMENT_OK = 0; @@ -46,10 +62,18 @@ class SystemManager { /** * Constructs a SystemManager object. + * + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. + * @param \Drupal\Core\Database\Connection $database + * The database connection. + * @param \Drupal\Core\Entity\EntityManager $entity_manager + * The entity manager. */ - public function __construct(ModuleHandlerInterface $module_handler, Connection $database) { + public function __construct(ModuleHandlerInterface $module_handler, Connection $database, EntityManager $entity_manager) { $this->moduleHandler = $module_handler; $this->database = $database; + $this->menuLinkStorage = $entity_manager->getStorageController('menu_link'); } /** @@ -137,7 +161,7 @@ public function getMaxSeverity(&$requirements) { */ public function getBlockContents() { $item = menu_get_item(); - if ($content = system_admin_menu_block($item)) { + if ($content = $this->getAdminBlock($item)) { $output = array( '#content' => $content, '#theme' => 'admin_block_content', @@ -151,4 +175,55 @@ public function getBlockContents() { } return $output; } + + /** + * Provide a single block on the administration overview page. + * + * @param $item + * The menu item to be displayed. + * + * @return array + */ + public function getAdminBlock($item) { + // If we are calling this function for a menu item that corresponds to a + // local task (for example, admin/tasks), then we want to retrieve the + // parent item's child links, not this item's (since this item won't have + // any). + if ($item['tab_root'] != $item['path']) { + $item = menu_get_item($item['tab_root_href']); + } + + if (!isset($item['mlid'])) { + $menu_links = $this->menuLinkStorage->loadByProperties('menu_link', array('router_path' => $item['path'], 'module' => 'system')); + $menu_link = reset($menu_links); + $item['mlid'] = $menu_link->id(); + $item['menu_name'] = $menu_link->menu_name; + } + + if (isset($this->menuItems[$item['mlid']])) { + return $this->menuItems[$item['mlid']]; + } + + $content = array(); + $menu_links = $this->menuLinkStorage->loadByProperties('menu_link', array('plid' => $item['mlid'], 'menu_name' => $item['menu_name'], 'hidden' => 0)); + foreach ($menu_links as $link) { + _menu_link_translate($link); + if ($link['access']) { + // The link description, either derived from 'description' in + // hook_menu() or customized via menu module is used as title attribute. + if (!empty($link['localized_options']['attributes']['title'])) { + $link['description'] = $link['localized_options']['attributes']['title']; + unset($link['localized_options']['attributes']['title']); + } + // Prepare for sorting as in function _menu_tree_check_access(). + // The weight is offset so it is always positive, with a uniform 5-digits. + $key = (50000 + $link['weight']) . ' ' . Unicode::strtolower($link['title']) . ' ' . $link['mlid']; + $content[$key] = $link; + } + } + ksort($content); + $this->menuItems[$item['mlid']] = $content; + return $content; + } + } diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index eb855fd..66b1381 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -16,7 +16,8 @@ function system_admin_config_page() { // Check for status report errors. // @todo Use depedancy injection in http://drupal.org/node/1987810. - if (Drupal::service('system.manager')->checkRequirements() && user_access('administer site configuration')) { + $system_manager = Drupal::service('system.manager'); + if ($system_manager->checkRequirements() && user_access('administer site configuration')) { drupal_set_message(t('One or more problems were detected with your Drupal installation. Check the status report for more information.', array('@status' => url('admin/reports/status'))), 'error'); } $blocks = array(); @@ -44,7 +45,7 @@ function system_admin_config_page() { } $block = $item; $block['content'] = ''; - $block['content'] .= theme('admin_block_content', array('content' => system_admin_menu_block($item))); + $block['content'] .= theme('admin_block_content', array('content' => $system_manager->getAdminBlock($item))); if (!empty($block['content'])) { $block['show'] = TRUE; } @@ -64,7 +65,7 @@ function system_admin_config_page() { } } - /** +/** * Menu callback; displays a listing of all themes. */ function system_themes_page() { diff --git a/core/modules/system/system.module b/core/modules/system/system.module index c3670c2..26d74bd 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2420,48 +2420,11 @@ function template_preprocess_system_plugin_ui_form(&$variables) { * * @param $item * The menu item to be displayed. + * + * @deprecated Use \Drupal\system\SystemManager::getAdminBlock(). */ function system_admin_menu_block($item) { - $cache = &drupal_static(__FUNCTION__, array()); - // If we are calling this function for a menu item that corresponds to a - // local task (for example, admin/tasks), then we want to retrieve the - // parent item's child links, not this item's (since this item won't have - // any). - if ($item['tab_root'] != $item['path']) { - $item = menu_get_item($item['tab_root_href']); - } - - if (!isset($item['mlid'])) { - $menu_links = entity_load_multiple_by_properties('menu_link', array('router_path' => $item['path'], 'module' => 'system')); - $menu_link = reset($menu_links); - $item['mlid'] = $menu_link->id(); - $item['menu_name'] = $menu_link->menu_name; - } - - if (isset($cache[$item['mlid']])) { - return $cache[$item['mlid']]; - } - - $content = array(); - $menu_links = entity_load_multiple_by_properties('menu_link', array('plid' => $item['mlid'], 'menu_name' => $item['menu_name'], 'hidden' => 0)); - foreach ($menu_links as $link) { - _menu_link_translate($link); - if ($link['access']) { - // The link description, either derived from 'description' in - // hook_menu() or customized via menu module is used as title attribute. - if (!empty($link['localized_options']['attributes']['title'])) { - $link['description'] = $link['localized_options']['attributes']['title']; - unset($link['localized_options']['attributes']['title']); - } - // Prepare for sorting as in function _menu_tree_check_access(). - // The weight is offset so it is always positive, with a uniform 5-digits. - $key = (50000 + $link['weight']) . ' ' . drupal_strtolower($link['title']) . ' ' . $link['mlid']; - $content[$key] = $link; - } - } - ksort($content); - $cache[$item['mlid']] = $content; - return $content; + return Drupal::service('system.manager')->getAdminBlock($item); } /** diff --git a/core/modules/system/system.services.yml b/core/modules/system/system.services.yml index 0c770d3..bfc0e8c 100644 --- a/core/modules/system/system.services.yml +++ b/core/modules/system/system.services.yml @@ -13,7 +13,7 @@ services: arguments: ['@container.namespaces'] system.manager: class: Drupal\system\SystemManager - arguments: ['@module_handler', '@database'] + arguments: ['@module_handler', '@database', '@plugin.manager.entity'] system.breadcrumb.legacy: class: Drupal\system\LegacyBreadcrumbBuilder tags: