diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 6209fac..cd8121d 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -2723,25 +2723,6 @@ function menu_router_build($save = FALSE) { $router_items = call_user_func($module . '_menu'); if (isset($router_items) && is_array($router_items)) { foreach (array_keys($router_items) as $path) { - // If the menu item is a default local task and incorrectly references a - // route, remove it. - // @todo This may be removed later depending on the outcome of - // http://drupal.org/node/1889790 - if (isset($router_items[$path]['type']) && $router_items[$path]['type'] == MENU_DEFAULT_LOCAL_TASK) { - unset($router_items[$path]['route_name']); - } - // If the menu item references a route, normalize the route information - // into the old structure. Note that routes are keyed by name, not path, - // so the path of the route takes precedence. - if (isset($router_items[$path]['route_name'])) { - $router_item = $router_items[$path]; - $router_item['page callback'] = 'USES_ROUTE'; - $router_item['access callback'] = TRUE; - $new_path = _menu_router_translate_route($router_item['route_name']); - unset($router_items[$path]); - $router_items[$new_path] = $router_item; - $path = $new_path; - } $router_items[$path]['module'] = $module; } $callbacks = array_merge($callbacks, $router_items); @@ -2749,6 +2730,26 @@ function menu_router_build($save = FALSE) { } // Alter the menu as defined in modules, keys are like user/%user. drupal_alter('menu', $callbacks); + foreach ($callbacks as $path => $router_item) { + // If the menu item is a default local task and incorrectly references a + // route, remove it. + // @todo This may be removed later depending on the outcome of + // http://drupal.org/node/1889790 + if (isset($router_item['type']) && $router_item['type'] == MENU_DEFAULT_LOCAL_TASK) { + unset($callbacks[$path]['route_name']); + } + // If the menu item references a route, normalize the route information + // into the old structure. Note that routes are keyed by name, not path, + // so the path of the route takes precedence. + if (isset($router_item['route_name'])) { + $router_item['page callback'] = 'USES_ROUTE'; + $router_item['access callback'] = TRUE; + $new_path = _menu_router_translate_route($router_item['route_name']); + + unset($callbacks[$path]); + $callbacks[$new_path] = $router_item; + } + } list($menu, $masks) = _menu_router_build($callbacks, $save); _menu_router_cache($menu); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php index bb05080..57691f1 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php @@ -27,6 +27,29 @@ public function hasPath() { } /** + * {@inheritdoc} + */ + public function getPath() { + $bits = explode('/', $this->getOption('path')); + if ($this->isDefaultTabPath()) { + array_pop($bits); + } + return implode('/', $bits); + } + + /** + * Determines if this display's path is a default tab. + * + * @return bool + * TRUE if the display path is for a default tab, FALSE otherwise. + */ + protected function isDefaultTabPath() { + $menu = $this->getOption('menu'); + $tab_options = $this->getOption('tab_options'); + return $menu['type'] == 'default tab' && !empty($tab_options['type']) && $tab_options['type'] != 'none'; + } + + /** * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase:defineOptions(). */ protected function defineOptions() { @@ -84,6 +107,14 @@ public function collectRoutes(RouteCollection $collection) { $bits[] = $bit; } + // If this is to be a default tab, create the route for the parent path. + if ($this->isDefaultTabPath()) { + $bit = array_pop($bits); + if ($bit == '%views_arg' || empty($bits)) { + $bits[] = $bit; + } + } + $route_path = '/' . implode('/', $bits); $route = new Route($route_path, $defaults); @@ -172,38 +203,42 @@ public function executeHookMenu($callbacks) { // If this is a 'default' tab, check to see if we have to create the // parent menu item. - if ($menu['type'] == 'default tab') { + if ($this->isDefaultTabPath()) { $tab_options = $this->getOption('tab_options'); - if (!empty($tab_options['type']) && $tab_options['type'] != 'none') { - $bits = explode('/', $path); - // Remove the last piece. - $bit = array_pop($bits); - - // we can't do this if they tried to make the last path bit variable. - // @todo: We can validate this. - if ($bit != '%views_arg' && !empty($bits)) { - $default_path = implode('/', $bits); - $items[$default_path] = array( - // Default views page entry. - // Identify URL embedded arguments and correlate them to a - // handler. - 'load arguments' => array($this->view->storage->id(), $this->display['id'], '%index'), - 'title' => $tab_options['title'], - 'description' => $tab_options['description'], - 'menu_name' => $tab_options['name'], - ); - switch ($tab_options['type']) { - default: - case 'normal': - $items[$default_path]['type'] = MENU_NORMAL_ITEM; - break; - case 'tab': - $items[$default_path]['type'] = MENU_LOCAL_TASK; - break; - } - if (isset($tab_options['weight'])) { - $items[$default_path]['weight'] = intval($tab_options['weight']); - } + + $bits = explode('/', $path); + // Remove the last piece. + $bit = array_pop($bits); + + // we can't do this if they tried to make the last path bit variable. + // @todo: We can validate this. + if ($bit != '%views_arg' && !empty($bits)) { + // Assign the route name to the parent route, not the default tab. + $default_route_name = $items[$path]['route_name']; + unset($items[$path]['route_name']); + + $default_path = implode('/', $bits); + $items[$default_path] = array( + // Default views page entry. + // Identify URL embedded arguments and correlate them to a + // handler. + 'load arguments' => array($this->view->storage->id(), $this->display['id'], '%index'), + 'title' => $tab_options['title'], + 'description' => $tab_options['description'], + 'menu_name' => $tab_options['name'], + 'route_name' => $default_route_name, + ); + switch ($tab_options['type']) { + default: + case 'normal': + $items[$default_path]['type'] = MENU_NORMAL_ITEM; + break; + case 'tab': + $items[$default_path]['type'] = MENU_LOCAL_TASK; + break; + } + if (isset($tab_options['weight'])) { + $items[$default_path]['weight'] = intval($tab_options['weight']); } } }