diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php index e92bc43..f984aa7 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php @@ -77,7 +77,6 @@ function testMenu() { $this->menu = $this->addCustomMenu(); $this->doMenuTests(); - return; $this->addInvalidMenuLink(); $this->addCustomMenuCRUD(); diff --git a/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php b/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php index c5696ca..b66eb69 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php @@ -482,10 +482,6 @@ public function preSave(EntityStorageInterface $storage) { // since a path marked as external does not need to match a route. $this->external = (url_is_external($this->link_path) || $this->link_path == '') ? 1 : 0; - /** @var \Drupal\menu_link\MenuTreeStorageInterface $menu_tree_storage */ - $menu_tree_storage = \Drupal::service('menu_link.tree_storage'); - $menu_tree_storage->preSaveMenuLink($this); - // Find the route_name. if (!isset($this->route_name)) { $url = Url::createFromPath($this->link_path); @@ -507,6 +503,8 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { /** @var \Drupal\menu_link\MenuTreeStorageInterface $menu_tree_storage */ $menu_tree_storage = \Drupal::service('menu_link.tree_storage'); + $menu_tree_storage->postSaveMenuLink($this); + // First store the menu tree information itself. $menu_tree_storage->saveNode($this); @@ -546,7 +544,7 @@ public static function postLoad(EntityStorageInterface $storage, array &$entitie // Load the menu tree information. if ($menu_tree_node = \Drupal::service('menu_link.tree_storage')->loadNode($menu_link->id())) { foreach ($menu_tree_node as $key => $value) { - $menu_tree_node->{$key} = $value; + $menu_link->{$key} = $value; } } } diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorage.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorage.php index a1494ad..d41088d 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorage.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorage.php @@ -174,6 +174,4 @@ public function createFromDefaultLink(array $item) { return $this->create($item); } - - } diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeStorage.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeStorage.php index bac8417..938b02f 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeStorage.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeStorage.php @@ -177,7 +177,7 @@ public function moveChildren(EntityInterface $entity) { /** * {@inheritdoc} */ - public function preSaveMenuLink(MenuLinkInterface $menu_link) { + public function postSaveMenuLink(MenuLinkInterface $menu_link) { $storage = \Drupal::entityManager()->getStorage('menu_link'); // Try to find a parent link. If found, assign it and derive its menu. $parent = $this->findParent($menu_link, $storage); @@ -282,7 +282,7 @@ public function loadNode($mlid) { $query = $this->database->select('menu_tree'); $query->fields('menu_tree'); $query->condition('mlid', $mlid); - $query->execute()->fetchAssoc(); + return $query->execute()->fetchAssoc(); } public function saveNode($menu_link) { diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeStorageInterface.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeStorageInterface.php index e4ecccf..3189a79 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeStorageInterface.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeStorageInterface.php @@ -51,7 +51,7 @@ public function moveChildren(EntityInterface $entity); * @param MenuLinkInterface $menu_link * @return */ - public function preSaveMenuLink(MenuLinkInterface $menu_link); + public function postSaveMenuLink(MenuLinkInterface $menu_link); /** * Sets an internal flag that allows us to prevent the reparenting operations diff --git a/core/modules/menu_link/menu_link.install b/core/modules/menu_link/menu_link.install index cd89417..9588e50 100644 --- a/core/modules/menu_link/menu_link.install +++ b/core/modules/menu_link/menu_link.install @@ -333,6 +333,7 @@ function menu_link_schema() { ), 'indexes' => array( 'menu_parents' => array('menu_name', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9'), + 'menu_plid_expand_child' => array('menu_name', 'plid', 'expanded', 'has_children'), ), 'primary key' => array('mlid'), ); diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 0f58cb2..c8e1c27 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -474,18 +474,20 @@ function toolbar_menu_navigation_links(&$tree) { function toolbar_get_rendered_subtrees() { $subtrees = array(); /** @var \Drupal\menu_link\MenuTreeInterface $menu_tree */ + // @TODO Refactor the code to use the menu tree functionality directly. $menu_tree = \Drupal::service('menu_link.tree'); + /** @var \Drupal\menu_link\MenuTreeStorageInterface $menu_tree_storage */ + $menu_tree_storage = \Drupal::service('menu_link.tree_storage'); $tree = toolbar_get_menu_tree(); foreach ($tree as $tree_item) { $item = $tree_item['link']; if (!$item['hidden'] && $item['access']) { if ($item['has_children']) { - $query = \Drupal::entityQuery('menu_link') - ->condition('has_children', 1); + $parameters = array(); for ($i=1; $i <= $item['depth']; $i++) { - $query->condition('p' . $i, $item['p' . $i]); + $parameters['p' . $i] = 'p' . $i; } - $parents = $query->execute(); + $parents = $menu_tree_storage->findNodes($parameters, $item['menu_name']); $subtree = $menu_tree->buildTree($item['menu_name'], array('expanded' => $parents, 'min_depth' => $item['depth']+1)); toolbar_menu_navigation_links($subtree); $subtree = $menu_tree->renderTree($subtree);