diff --git a/core/includes/menu.inc b/core/includes/menu.inc index b5adbba..1f3d78c 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -2682,6 +2682,8 @@ function menu_get_router() { * Builds menu links for the items in the menu router. */ function _menu_navigation_links_rebuild($menu) { + $menu_link_controller = entity_get_controller('menu_link'); + // Add normal and suggested items as links. $router_items = array(); foreach ($menu as $path => $router_item) { @@ -2699,10 +2701,17 @@ function _menu_navigation_links_rebuild($menu) { array_multisort($sort, SORT_NUMERIC, $router_items); foreach ($router_items as $key => $router_item) { - if ($existing_item = entity_load_multiple_by_properties('menu_link', array('link_path' => $router_item['path'], 'module' => 'system'))) { + $existing_item = db_select('menu_links') + ->fields('menu_links') + ->condition('link_path', $router_item['path']) + ->condition('module', 'system') + ->execute()->fetchAll(); + if ($existing_item) { $existing_item = reset($existing_item); + $existing_item->options = unserialize($existing_item->options); - $router_item['mlid'] = $existing_item->id(); + $router_item['mlid'] = $existing_item->mlid; + $router_item['uuid'] = $existing_item->uuid; // A change in hook_menu may move the link to a different menu if (empty($router_item['menu_name']) || ($router_item['menu_name'] == $existing_item->menu_name)) { $router_item['menu_name'] = $existing_item->menu_name; @@ -2722,13 +2731,13 @@ function _menu_navigation_links_rebuild($menu) { } if ($existing_item && $existing_item->customized) { - $parent_candidates[$existing_item->id()] = $existing_item; + $parent_candidates[$existing_item->mlid] = $existing_item; } else { $menu_link = MenuLink::buildFromRouterItem($router_item); $menu_link->original = $existing_item; $menu_link->parentCandidates = $parent_candidates; - $menu_link->save(); + $menu_link_controller->save($menu_link); $parent_candidates[$menu_link->id()] = $menu_link; unset($router_items[$key]); } @@ -2747,7 +2756,7 @@ function _menu_navigation_links_rebuild($menu) { $menu_link->router_path = $router_path; $menu_link->updated = (int) $updated; - $menu_link->save(); + $menu_link_controller->save($menu_link); } } 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 55592b9..a9f7142 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php @@ -473,7 +473,7 @@ protected function setParents(EntityInterface $entity, EntityInterface $parent) * @return int * The relative depth, or zero. */ - public function findChildrenRelativeDepth(EntityInterface $entity) { + public function findChildrenRelativeDepth($entity) { // @todo Since all we need is a specific field from the base table, does it // make sense to convert to EFQ? $query = db_select('menu_links'); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 1e8a2d4..e3c6a16 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -2043,19 +2043,21 @@ function system_update_8035() { * Creates the langcode and UUID columns for menu links and adds the * 'serialize' property to the options column. */ -function system_update_8035() { +function system_update_8036() { // Enable the module without re-installing the schema. update_module_enable(array('menu_link')); - // Add the langcode column. - $column = array( - 'description' => 'The {language}.langcode of this entity.', - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - ); - db_add_field('menu_links', 'langcode', $column); + // Add the langcode column if it doesn't exist. + if (!db_field_exists('menu_links', 'langcode')) { + $column = array( + 'description' => 'The {language}.langcode of this entity.', + 'type' => 'varchar', + 'length' => 12, + 'not null' => TRUE, + 'default' => '', + ); + db_add_field('menu_links', 'langcode', $column); + } // Add the UUID column. $column = array(