예제 #1
0
 /**
  * Provide a single block on the administration overview page.
  *
  * @param \Drupal\menu_link\MenuLinkInterface|array $item
  *   The menu item to be displayed.
  *
  * @return array
  *   An array of menu items, as expected by theme_admin_block_content().
  */
 public function getAdminBlock($item)
 {
     if (!isset($item['mlid'])) {
         $menu_links = $this->menuLinkStorage->loadByProperties(array('link_path' => $item['path'], 'module' => 'system'));
         if ($menu_links) {
             $menu_link = reset($menu_links);
             $item['mlid'] = $menu_link->id();
             $item['menu_name'] = $menu_link->menu_name;
         } else {
             return array();
         }
     }
     if (isset($this->menuItems[$item['mlid']])) {
         return $this->menuItems[$item['mlid']];
     }
     $content = array();
     $menu_links = $this->menuLinkStorage->loadByProperties(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 UI 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;
 }