diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php index b29cdca..d25e81d 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php @@ -20,6 +20,8 @@ class MenuLinkStorageController extends DatabaseStorageController { /** + * Indicates whether the delete operation should re-parent children items. + * * @var bool */ protected $preventReparenting = FALSE; @@ -305,7 +307,7 @@ public function loadUpdatedCustomized(array $router_paths) { /** * Loads system menu link as needed by system_get_module_admin_tasks(). * - * @return array + * @return array * An array of menu link entities indexed by their IDs. */ public function loadModuleAdminTasks() { diff --git a/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php b/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php index 9d41851..bccbb67 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php @@ -84,56 +84,83 @@ class MenuLink extends Entity implements \ArrayAccess, ContentEntityInterface { public $router_path; /** + * The entity label. + * * @var string */ public $link_title = ''; /** + * A serialized array of options to be passed to the url() or l() function, + * such as a query string or HTML attributes. + * * @var array */ public $options = array(); /** + * The name of the module that generated this link. + * * @var string */ public $module = 'menu'; /** + * A flag for whether the link should be rendered in menus. + * * @var int */ public $hidden = 0; /** + * A flag to indicate if the link points to a full URL starting with a + * protocol, like http:// (1 = external, 0 = internal). + * * @var int */ public $external; /** + * Flag indicating whether any links have this link as a parent. + * * @var int */ public $has_children = 0; /** + * Flag for whether this link should be rendered as expanded in menus. + * Expanded links always have their child links displayed, instead of only + * when the link is in the active trail. + * * @var int */ public $expanded = 0; /** + * Link weight among links in the same menu at the same depth. + * * @var int */ public $weight = 0; /** + * The depth relative to the top level. A link with plid == 0 will have + * depth == 1. + * * @var int */ public $depth; /** + * A flag to indicate that the user has manually created or edited the link. + * * @var int */ public $customized = 0; /** + * The first entity ID in the materialized path. + * * @var int * * @todo Investigate whether the p1, p2, .. pX properties can be moved to a @@ -142,41 +169,57 @@ class MenuLink extends Entity implements \ArrayAccess, ContentEntityInterface { public $p1; /** + * The second entity ID in the materialized path. + * * @var int */ public $p2; /** + * The third entity ID in the materialized path. + * * @var int */ public $p3; /** + * The fourth entity ID in the materialized path. + * * @var int */ public $p4; /** + * The fifth entity ID in the materialized path. + * * @var int */ public $p5; /** + * The sixth entity ID in the materialized path. + * * @var int */ public $p6; /** + * The seventh entity ID in the materialized path. + * * @var int */ public $p7; /** + * The eighth entity ID in the materialized path. + * * @var int */ public $p8; /** + * The ninth entity ID in the materialized path. + * * @var int */ public $p9; diff --git a/core/modules/menu_link/menu_link.module b/core/modules/menu_link/menu_link.module index d18598d..ed11c78 100644 --- a/core/modules/menu_link/menu_link.module +++ b/core/modules/menu_link/menu_link.module @@ -32,7 +32,7 @@ function menu_link_uri(MenuLink $menu_link) { * (optional) Whether to reset the menu_link_load_multiple() cache. * * @return \Drupal\menu_link\Plugin\Core\Entity\MenuLink|false - * A menu link entity. + * A menu link entity, or FALSE if there is no entity with the given ID. */ function menu_link_load($mlid = NULL, $reset = FALSE) { return entity_load('menu_link', $mlid, $reset); @@ -47,7 +47,7 @@ function menu_link_load($mlid = NULL, $reset = FALSE) { * (optional) Whether to reset the internal cache. * * @return array<\Drupal\menu_link\Plugin\Core\Entity\MenuLink> - * An array of menu link entities indexed by mlid. + * An array of menu link entities indexed by entity IDs. * * @see menu_link_load() * @see entity_load_multiple() @@ -121,34 +121,6 @@ function menu_link_save(MenuLink $menu_link) { } /** - * Clones an array of menu links. - * - * @param array $links - * An array of menu links to clone. - * @param string $menu_name - * (optional) The name of a menu that the links will be cloned for. If not - * set, the cloned links will be in the same menu as the original set of - * links that were passed in. - * - * @return array - * An array of menu links with the same properties as the passed-in array, - * but with the link identifiers removed so that a new link will be created - * when any of them is passed into - * Drupal\menu_link\MenuLinkStorageController::save(). - * - * @see Drupal\menu_link\MenuLinkStorageController::save() - */ -function menu_link_clone($links, $menu_name = NULL) { - foreach ($links as &$link) { - $link = $link->createDuplicate(); - if (isset($menu_name)) { - $link->menu_name = $menu_name; - } - } - return $links; -} - -/** * Inserts, updates, enables, disables, or deletes an uncustomized menu link. * * @param string $module diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index c4da3fa..99f67ae 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -338,18 +338,6 @@ function shortcut_set_load($id) { } /** - * Implements hook_shortcut_load(). - * - * Loads menu links attached to each of shortcuts. - */ -function shortcut_shortcut_load($entities) { - foreach ($entities as $id => $entity) { - // @todo Decide whether we want to load the links dynamically like that. -// $entity->set('links', menu_load_links('shortcut-' . $id)); - } -} - -/** * Resets the link weights in a shortcut set to match their current order. * * This function can be used, for example, when a new shortcut link is added to diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/TreeOutputTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/TreeOutputTest.php index 7e09d18..01794f0 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/TreeOutputTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/TreeOutputTest.php @@ -7,13 +7,15 @@ namespace Drupal\system\Tests\Menu; -use Drupal\menu_link\Plugin\Core\Entity\MenuLink; -use Drupal\simpletest\WebTestBase; +use Drupal\simpletest\DrupalUnitTestBase; /** * Menu tree output related tests. */ -class TreeOutputTest extends WebTestBase { +class TreeOutputTest extends DrupalUnitTestBase { + + public static $modules = array('system', 'menu_link'); + /** * Dummy link structure acceptable for menu_tree_output(). */ @@ -29,30 +31,33 @@ public static function getInfo() { function setUp() { parent::setUp(); + + $this->installSchema('system', 'menu_router'); } /** * Validate the generation of a proper menu tree output. */ function testMenuTreeData() { + $storage_controller = $this->container->get('plugin.manager.entity')->getStorageController('menu_link'); // @todo Prettify this tree buildup code, it's very hard to read. $this->tree_data = array( '1'=> array( - 'link' => new MenuLink(array('menu_name' => 'main-menu', 'mlid' => 1, 'hidden' => 0, 'has_children' => 1, 'title' => 'Item 1', 'in_active_trail' => 1, 'access' => 1, 'href' => 'a', 'localized_options' => array('attributes' => array('title' =>''))), 'menu_link'), + 'link' => $storage_controller->create(array('menu_name' => 'main-menu', 'mlid' => 1, 'hidden' => 0, 'has_children' => 1, 'title' => 'Item 1', 'in_active_trail' => 1, 'access' => 1, 'href' => 'a', 'localized_options' => array('attributes' => array('title' =>'')))), 'below' => array( - '2' => array('link' => new MenuLink(array('menu_name' => 'main-menu', 'mlid' => 2, 'hidden' => 0, 'has_children' => 1, 'title' => 'Item 2', 'in_active_trail' => 1, 'access' => 1, 'href' => 'a/b', 'localized_options' => array('attributes' => array('title' =>''))), 'menu_link'), + '2' => array('link' => $storage_controller->create(array('menu_name' => 'main-menu', 'mlid' => 2, 'hidden' => 0, 'has_children' => 1, 'title' => 'Item 2', 'in_active_trail' => 1, 'access' => 1, 'href' => 'a/b', 'localized_options' => array('attributes' => array('title' =>'')))), 'below' => array( - '3' => array('link' => new MenuLink(array('menu_name' => 'main-menu', 'mlid' => 3, 'hidden' => 0, 'has_children' => 0, 'title' => 'Item 3', 'in_active_trail' => 0, 'access' => 1, 'href' => 'a/b/c', 'localized_options' => array('attributes' => array('title' =>''))), 'menu_link'), + '3' => array('link' => $storage_controller->create(array('menu_name' => 'main-menu', 'mlid' => 3, 'hidden' => 0, 'has_children' => 0, 'title' => 'Item 3', 'in_active_trail' => 0, 'access' => 1, 'href' => 'a/b/c', 'localized_options' => array('attributes' => array('title' =>'')))), 'below' => array() ), - '4' => array('link' => new MenuLink(array('menu_name' => 'main-menu', 'mlid' => 4, 'hidden' => 0, 'has_children' => 0, 'title' => 'Item 4', 'in_active_trail' => 0, 'access' => 1, 'href' => 'a/b/d', 'localized_options' => array('attributes' => array('title' =>''))), 'menu_link'), + '4' => array('link' => $storage_controller->create(array('menu_name' => 'main-menu', 'mlid' => 4, 'hidden' => 0, 'has_children' => 0, 'title' => 'Item 4', 'in_active_trail' => 0, 'access' => 1, 'href' => 'a/b/d', 'localized_options' => array('attributes' => array('title' =>'')))), 'below' => array() ) ) ) ) ), - '5' => array('link' => new MenuLink(array('menu_name' => 'main-menu', 'mlid' => 5, 'hidden' => 1, 'has_children' => 0, 'title' => 'Item 5', 'in_active_trail' => 0, 'access' => 1, 'href' => 'e', 'localized_options' => array('attributes' => array('title' =>''))), 'menu_link'), 'below' => array()), - '6' => array('link' => new MenuLink(array('menu_name' => 'main-menu', 'mlid' => 6, 'hidden' => 0, 'has_children' => 0, 'title' => 'Item 6', 'in_active_trail' => 0, 'access' => 0, 'href' => 'f', 'localized_options' => array('attributes' => array('title' =>''))), 'menu_link'), 'below' => array()), - '7' => array('link' => new MenuLink(array('menu_name' => 'main-menu', 'mlid' => 7, 'hidden' => 0, 'has_children' => 0, 'title' => 'Item 7', 'in_active_trail' => 0, 'access' => 1, 'href' => 'g', 'localized_options' => array('attributes' => array('title' =>''))), 'menu_link'), 'below' => array()) + '5' => array('link' => $storage_controller->create(array('menu_name' => 'main-menu', 'mlid' => 5, 'hidden' => 1, 'has_children' => 0, 'title' => 'Item 5', 'in_active_trail' => 0, 'access' => 1, 'href' => 'e', 'localized_options' => array('attributes' => array('title' =>'')))), 'below' => array()), + '6' => array('link' => $storage_controller->create(array('menu_name' => 'main-menu', 'mlid' => 6, 'hidden' => 0, 'has_children' => 0, 'title' => 'Item 6', 'in_active_trail' => 0, 'access' => 0, 'href' => 'f', 'localized_options' => array('attributes' => array('title' =>'')))), 'below' => array()), + '7' => array('link' => $storage_controller->create(array('menu_name' => 'main-menu', 'mlid' => 7, 'hidden' => 0, 'has_children' => 0, 'title' => 'Item 7', 'in_active_trail' => 0, 'access' => 1, 'href' => 'g', 'localized_options' => array('attributes' => array('title' =>'')))), 'below' => array()) ); $output = menu_tree_output($this->tree_data); diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index cd84470..38eac66 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -29,29 +29,29 @@ function system_admin_config_page() { $result = $query->execute(); if (!empty($result)) { $menu_links = menu_link_load_multiple($result); - } - foreach ($menu_links as $item) { - _menu_link_translate($item); - if (!$item['access']) { - continue; - } - // The link description, either derived from 'description' in hook_menu() - // or customized via menu module is used as title attribute. - if (!empty($item['localized_options']['attributes']['title'])) { - $item['description'] = $item['localized_options']['attributes']['title']; - unset($item['localized_options']['attributes']['title']); - } - $block = $item; - $block['content'] = ''; - $block['content'] .= theme('admin_block_content', array('content' => system_admin_menu_block($item))); - if (!empty($block['content'])) { - $block['show'] = TRUE; - } + foreach ($menu_links as $item) { + _menu_link_translate($item); + if (!$item['access']) { + continue; + } + // The link description, either derived from 'description' in hook_menu() + // or customized via menu module is used as title attribute. + if (!empty($item['localized_options']['attributes']['title'])) { + $item['description'] = $item['localized_options']['attributes']['title']; + unset($item['localized_options']['attributes']['title']); + } + $block = $item; + $block['content'] = ''; + $block['content'] .= theme('admin_block_content', array('content' => system_admin_menu_block($item))); + if (!empty($block['content'])) { + $block['show'] = TRUE; + } - // Prepare for sorting as in function _menu_tree_check_access(). - // The weight is offset so it is always positive, with a uniform 5-digits. - $blocks[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $block; + // Prepare for sorting as in function _menu_tree_check_access(). + // The weight is offset so it is always positive, with a uniform 5-digits. + $blocks[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $block; + } } } if ($blocks) { diff --git a/core/modules/user/user.module b/core/modules/user/user.module index a3f76a5..7f0fe42 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1121,7 +1121,7 @@ function user_menu_site_status_alter(&$menu_site_status, $path) { /** * Implements hook_menu_link_presave(). */ -function user_menu_link_presave($link) { +function user_menu_link_alter(&$link) { // The path 'user' must be accessible for anonymous users, but only visible // for authenticated users. Authenticated users should see "My account", but // anonymous users should not see it at all. Therefore, invoke diff --git a/core/profiles/minimal/minimal.info b/core/profiles/minimal/minimal.info index 5276bb2..545e85c 100644 --- a/core/profiles/minimal/minimal.info +++ b/core/profiles/minimal/minimal.info @@ -2,7 +2,6 @@ name = Minimal description = Build a custom site without pre-configured functionality. Suitable for advanced users. version = VERSION core = 8.x -dependencies[] = menu_link dependencies[] = node dependencies[] = block dependencies[] = dblog diff --git a/core/profiles/testing/testing.info b/core/profiles/testing/testing.info index fcbe479..fff3df2 100644 --- a/core/profiles/testing/testing.info +++ b/core/profiles/testing/testing.info @@ -3,6 +3,5 @@ description = Minimal profile for running tests. Includes absolutely required mo version = VERSION core = 8.x hidden = TRUE -dependencies[] = menu_link ; @todo Remove dependency on Node module. dependencies[] = node