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 b66eb69..0184a7e 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 @@ -436,8 +436,10 @@ public static function preDelete(EntityStorageInterface $storage, array $entitie foreach ($entities as $entity) { // Children get re-attached to the item's parent. if ($entity->has_children) { - $children = $storage->loadByProperties(array('plid' => $entity->plid)); + $mlids = $menu_tree_storage->findNodes(array('plid' => $entity->plid)); + $children = $storage->loadMultiple($mlids); foreach ($children as $child) { +// $menu_tree_storage->reparentNode($child, $entity->plid); $child->plid = $entity->plid; $storage->save($child); } @@ -456,6 +458,7 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti /** @var \Drupal\menu_link\MenuTreeStorageInterface $menu_tree_storage */ $menu_tree_storage = \Drupal::service('menu_link.tree_storage'); foreach ($entities as $entity) { + $menu_tree_storage->deleteNode($entity); if (!$menu_tree_storage->getPreventReparenting()) { $menu_tree_storage->updateParentalStatus($entity); } 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 d41088d..682bdc1 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorage.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorage.php @@ -139,16 +139,14 @@ public function loadModuleAdminTasks() { $result->addField('menu_links', 'mlid'); $plid = $result->execute()->fetchField(); - $query = $this->database->select('menu_links', 'base', array('fetch' => \PDO::FETCH_ASSOC)); - $query->fields('base'); - $query - ->condition('base.hidden', 0, '>=') - ->condition('base.module', '', '>') - ->condition('base.machine_name', '', '>') - ->condition('base.p1', $plid); - $entities = $query->execute()->fetchAll(); + /** @var \Drupal\menu_link\MenuTreeStorageInterface $menu_tree_storage */ + $menu_tree_storage = \Drupal::service('menu_link.tree_storage'); + $mlids = $menu_tree_storage->findNodes(array( + 'p1' => $plid, + 'hidden' => 0, + ), 'admin'); - return $entities; + return $this->loadMultiple($mlids); } /** 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 938b02f..3441c04 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeStorage.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeStorage.php @@ -249,13 +249,15 @@ public function getExpandedParents(array $parents, $menu_name) { return $result; } - public function findNodes($parameters, $menu_name) { + public function findNodes($parameters, $menu_name = '') { $query = $this->database->select('menu_tree'); $query->addField('menu_tree', 'mlid'); for ($i = 1; $i <= MENU_MAX_DEPTH; $i++) { $query->orderBy('p' . $i, 'ASC'); } - $query->condition('menu_name', $menu_name); + if ($menu_name) { + $query->condition('menu_name', $menu_name); + } if (!empty($parameters['expanded'])) { $query->condition('plid', $parameters['expanded'], 'IN'); } @@ -286,7 +288,6 @@ public function loadNode($mlid) { } public function saveNode($menu_link) { - $values = array(); foreach (array('menu_name', 'mlid', 'plid', 'has_children', 'weight', 'expanded', 'depth', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9') as $key) { $values[$key] = $menu_link[$key]; @@ -298,5 +299,14 @@ public function saveNode($menu_link) { ->execute(); } + public function deleteNode($menu_link) { + $this->database->delete('menu_tree') + ->condition('mlid', $menu_link['mlid']) + ->execute(); + } + + public function reparentNode($menu_link, $new_plid) { + } + } 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 3189a79..5ac542a 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeStorageInterface.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuTreeStorageInterface.php @@ -73,11 +73,15 @@ public function getPreventReparenting(); public function getExpandedParents(array $parents, $menu_name); - public function findNodes($parameters, $menu_name); + public function findNodes($parameters, $menu_name = ''); public function loadNode($mlid); public function saveNode($menu_link); + public function deleteNode($menu_link); + + public function reparentNode($menu_link, $new_plid); + } diff --git a/core/modules/toolbar/lib/Drupal/toolbar/Tests/ToolbarAdminMenuTest.php b/core/modules/toolbar/lib/Drupal/toolbar/Tests/ToolbarAdminMenuTest.php index 01f043e..aca6260 100644 --- a/core/modules/toolbar/lib/Drupal/toolbar/Tests/ToolbarAdminMenuTest.php +++ b/core/modules/toolbar/lib/Drupal/toolbar/Tests/ToolbarAdminMenuTest.php @@ -134,18 +134,13 @@ function testModuleStatusChangeSubtreesHashCacheClear() { */ function testMenuLinkUpdateSubtreesHashCacheClear() { // Get subtree items for the admin menu. - $query = \Drupal::entityQuery('menu_link'); - for ($i = 1; $i <= 3; $i++) { - $query->sort('p' . $i, 'ASC'); - } - $query->condition('menu_name', 'admin'); - $query->condition('depth', '2', '>='); + /** @var \Drupal\menu_link\MenuTreeStorageInterface $menu_tree_storage */ + $menu_tree_storage = \Drupal::service('menu_link.tree_storage'); + $result = $menu_tree_storage->findNodes(array('min_depth' => 2), 'admin'); // Build an ordered array of links using the query result object. - $links = array(); - if ($result = $query->execute()) { - $links = menu_link_load_multiple($result); - } + $links = menu_link_load_multiple($result); + // Get the first link in the set. $links = array_values($links); $link = array_shift($links);