diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 10deda6..014b78f 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -2784,34 +2784,18 @@ function menu_get_router() { * Recursive helper to save menu links. */ function _menu_link_save_recursive($controller, $machine_name, &$children, &$links) { - $link = $links[$machine_name]; - if (!isset($link['plid']) && !empty($link['parent']) && !empty($links[$link['parent']])) { - $parent = $links[$link['parent']]; - if (empty($link['menu_name']) || $parent['menu_name'] == $link['menu_name']) { - $link['plid'] = $parent['mlid']; + $menu_link = $links[$machine_name]; + if ($menu_link->isNew() || !$menu_link->customized) { + if (!isset($menu_link->plid) && !empty($menu_link->parent) && !empty($links[$menu_link->parent])) { + $parent = $links[$menu_link->parent]; + + if (empty($menu_link->menu_name) || $parent->menu_name == $menu_link->menu_name) { + $menu_link->plid = $parent->id(); + $menu_link->menu_name = $parent->menu_name; + } } + $controller->save($menu_link); } - // Note, we set this as 'system', so that we can be sure to distinguish all - // the menu links generated automatically from hook_default_menu_links(). - $link['module'] = 'system'; - $link += array( - 'type' => MENU_NORMAL_ITEM, - 'hidden' => 0, - 'options' => empty($link['description']) ? array() : array('attributes' => array('title' => $link['description'])), - ); - // Suggested items are disabled by default. - if ($link['type'] == MENU_SUGGESTED_ITEM) { - $link['hidden'] = 1; - } - // Hide all items that are not visible in the tree. - elseif (!($link['type'] & MENU_VISIBLE_IN_TREE)) { - $link['hidden'] = -1; - } - - $entity = $controller->create($link); - $controller->save($entity); - // Update the uuid, mlid, etc. - $links[$machine_name] = get_object_vars($entity); if (!empty($children[$machine_name])) { foreach ($children[$machine_name] as $next_name) { _menu_link_save_recursive($controller, $next_name, $children, $links); @@ -2838,17 +2822,21 @@ function menu_default_links_rebuild() { foreach (Drupal::moduleHandler()->getImplementations('default_menu_links') as $module) { $default_links = call_user_func($module . '_default_menu_links'); foreach ($default_links as $machine_name => $link) { - // Note, we set this as 'system', so that we can be sure to distinguish - // the menu links generated automatically from entries in - // hook_default_menu_links(). - $link['machine_name'] = $machine_name; - if (!empty($link['parent'])) { - $children[$link['parent']][$machine_name] = $machine_name; + // Note, we set this as 'system', so that we can be sure to distinguish all + // the menu links generated automatically from hook_default_menu_links(). + $link['module'] = 'system'; + $link += array( + 'type' => MENU_NORMAL_ITEM, + 'hidden' => 0, + 'options' => empty($link['description']) ? array() : array('attributes' => array('title' => $link['description'])), + ); + // Suggested items are disabled by default. + if ($link['type'] == MENU_SUGGESTED_ITEM) { + $link['hidden'] = 1; } - else { - // A top level link - we need them to root our tree. - $top_links[$machine_name] = $machine_name; - $link['plid'] = 0; + // Hide all items that are not visible in the tree. + elseif (!($link['type'] & MENU_VISIBLE_IN_TREE)) { + $link['hidden'] = -1; } // For performance reasons, do a straight query now and convert to a menu // link entity later. @@ -2857,38 +2845,45 @@ function menu_default_links_rebuild() { ->fields('menu_links') ->condition('machine_name', $machine_name) ->condition('module', 'system') - ->execute()->fetchAll(); + ->execute()->fetchAssoc(); if ($existing_item) { - $existing_item = reset($existing_item); - $existing_item->options = unserialize($existing_item->options); - - $link['mlid'] = $existing_item->mlid; - $link['uuid'] = $existing_item->uuid; - // A change in hook_menu may move the link to a different menu - if (empty($link['menu_name']) || ($link['menu_name'] == $existing_item->menu_name)) { - $link['menu_name'] = $existing_item->menu_name; - $link['plid'] = $existing_item->plid; + $existing_item['options'] = unserialize($existing_item['options']); + $existing_item['route_parameters'] = unserialize($existing_item['route_parameters']); + $existing_item = $menu_link_controller->create($existing_item); + $menu_link = $existing_item; + if (!$menu_link->customized) { + // A change in hook_menu may move the link to a different menu + if (!empty($link['menu_name']) && ($link['menu_name'] != $existing_item->menu_name)) { + $menu_link->plid = NULL; + } + // Since the comparison in drupal_write_record just compares based on + // get_objet_vars(), there is no value to converting to an entity here. + $menu_link->original = clone $existing_item; } - else { - // It moved to a new menu. - // Let Drupal\menu_link\MenuLinkStorageController::save() try to find - // a new parent. - unset($link['plid']); + } + else { + if (empty($link['route_name']) && empty($link['link_path'])) { + $link['route_name'] = ''; } - $link['has_children'] = $existing_item->has_children; - $link['updated'] = $existing_item->updated; - // Since the comparison in drupal_write_record just compares based on - // get_objet_vars(), there is no value to converting to an entity here. - $link['original'] = $existing_item; + $menu_link = $menu_link_controller->create($link); + // Overwrite the default. + if (empty($link['menu_name'])) { + $menu_link->menu_name = NULL; + } + } + if (!empty($link['parent'])) { + $children[$link['parent']][$machine_name] = $machine_name; + $menu_link->parent = $link['parent']; } - if (empty($link['route_name']) && empty($link['link_path'])) { - $link['route_name'] = ''; + else { + // A top level link - we need them to root our tree. + $top_links[$machine_name] = $machine_name; + $menu_link->plid = 0; } - - $links[$machine_name] = $link; + $links[$machine_name] = $menu_link; } } - + debug($top_links, NULL, 1); foreach ($top_links as $machine_name) { _menu_link_save_recursive($menu_link_controller, $machine_name, $children, $links); } @@ -2896,7 +2891,7 @@ function menu_default_links_rebuild() { foreach ($children as $missing_parent => $orphan_links) { foreach ($orphan_links as $machine_name) { // Force it to the top level. - $links[$machine_name]['plid'] = 0; + $links[$machine_name]->plid = 0; _menu_link_save_recursive($menu_link_controller, $machine_name, $children, $links); } } diff --git a/core/modules/system/lib/Drupal/system/Controller/SystemController.php b/core/modules/system/lib/Drupal/system/Controller/SystemController.php index 03f516f..aeae612 100644 --- a/core/modules/system/lib/Drupal/system/Controller/SystemController.php +++ b/core/modules/system/lib/Drupal/system/Controller/SystemController.php @@ -103,7 +103,7 @@ public function overview() { // https://drupal.org/node/1987814. $block['content'] = array( '#theme' => 'admin_block_content', - '#content' => system_admin_menu_block($this->request), + '#content' => system_admin_menu_block($item), ); if (!empty($block['content'])) { @@ -140,7 +140,7 @@ public function overview() { */ public function compactPage($mode) { user_cookie_save(array('admin_compact_mode' => ($mode == 'on'))); - return $this->redirect('front'); + return $this->redirect(findChildrenRelativeDepth); } } diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 4fb7951..bcbd498 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -9,6 +9,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Symfony\Cmf\Component\Routing\RouteObjectInterface; /** * Provide a single block from the administration menu as a page. @@ -23,7 +24,17 @@ */ function system_admin_menu_block_page() { $request = Drupal::request(); - if ($content = system_admin_menu_block($request)) { + // Look for a link saved by system_default_menu_links(). + $properties = array('module' => 'system'); + if ($route_name = $request->attributes->get(RouteObjectInterface::ROUTE_NAME)) { + $properties['route_name'] = $route_name; + } + else { + $properties['link_path'] = current_path(); + } + $menu_links = entity_load_multiple_by_properties('menu_link', $properties); + $menu_link = reset($menu_links); + if ($content = system_admin_menu_block($menu_link)) { $output = theme('admin_block_content', array('content' => $content)); } else { diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 5ec0c7c..a6f4987 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -15,7 +15,6 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Guzzle\Http\Exception\BadResponseException; use Guzzle\Http\Exception\RequestException; @@ -1065,6 +1064,7 @@ function system_default_menu_links() { $items['admin/config/regional'] = array( 'link_path' => 'admin/config/regional', 'link_title' => 'Regional and language', + 'parent' => 'admin/config', 'description' => 'Regional settings, localization and translation.', 'weight' => -5, ); @@ -1096,6 +1096,7 @@ function system_default_menu_links() { $items['admin/config/system'] = array( 'link_title' => 'System', 'link_path' => 'admin/config/system', + 'parent' => 'admin/config', 'description' => 'General system related configuration.', 'weight' => -20, ); @@ -2527,22 +2528,10 @@ function system_preprocess_block(&$variables) { * Provide a single block on the administration overview page. * * @param $item - * The menu item to be displayed. + * The route name or path of the menu link to be displayed. */ -function system_admin_menu_block(Request $request) { +function system_admin_menu_block(\Drupal\menu_link\MenuLinkInterface $menu_link = NULL) { $cache = &drupal_static(__FUNCTION__, array()); - $menu_link = NULL; - - // Look for a link saved by system_default_menu_links(). - $properties = array('module' => 'system'); - if ($route_name = $request->attributes->get(RouteObjectInterface::ROUTE_NAME)) { - $properties['route_name'] = $route_name; - } - else { - $properties['link_path'] = current_path(); - } - $menu_links = entity_load_multiple_by_properties('menu_link', $properties); - $menu_link = reset($menu_links); if (empty($menu_link)) { return;