diff --git a/core/modules/views/src/Plugin/Derivative/ViewsLocalTask.php b/core/modules/views/src/Plugin/Derivative/ViewsLocalTask.php index c89bac3..2f27888 100644 --- a/core/modules/views/src/Plugin/Derivative/ViewsLocalTask.php +++ b/core/modules/views/src/Plugin/Derivative/ViewsLocalTask.php @@ -137,6 +137,8 @@ public function alterLocalTasks(&$local_tasks) { // We already have set the base_route for default tabs. $plugin_id = 'view.' . $executable->storage->id() . '.' . $display_id; + $apply_base_route = FALSE; + $is_parent = FALSE; if ($menu['type'] == 'tab') { $view_route_name = $view_route_names[$executable->storage->id() . '.' . $display_id]; @@ -146,46 +148,34 @@ public function alterLocalTasks(&$local_tasks) { continue; } - $this->applyBaseRoute($executable, $plugin_id, $local_tasks); + $apply_base_route = TRUE; } // Although the base route for the default tab has been taken care of, we // would still have to adjust the parent tab, if it's being created. elseif ($menu['type'] == 'default tab') { $tab_options = $executable->display_handler->getOption('tab_options'); if ($tab_options['type'] == 'tab') { - $this->applyBaseRoute($executable, $plugin_id, $local_tasks, TRUE); + $apply_base_route = TRUE; + $is_parent = TRUE; } } - } - } - - /** - * Apply the proper base route to a local task. - * - * @param \Drupal\views\ViewExecutable $view - * The View executable providing the local task. - * @param string $plugin_id - * The identifier for the display plugin. - * @param array $local_tasks - * The set of all local tasks, which will be adjusted. - * @param bool $is_parent - * Notifying that we want a parent local task. - */ - protected function applyBaseRoute(ViewExecutable $view, $plugin_id, &$local_tasks, $is_parent = FALSE) { - // Find out the parent route. - // @todo Find out how to find both the root and parent tab. - $path = $view->display_handler->getPath(); - $split = explode('/', $path); - array_pop($split); - $path = implode('/', $split); - - $pattern = '/' . str_replace('%', '{}', $path); - if ($routes = $this->routeProvider->getRoutesByPattern($pattern)) { - foreach ($routes->all() as $name => $route) { - $local_task_key = 'views_view:' . $plugin_id . ($is_parent ? '.parent' : ''); - $local_tasks[$local_task_key]['base_route'] = $name; - // Skip after the first found route. - break; + if ($apply_base_route) { + // Find out the parent route. + // @todo Find out how to find both the root and parent tab. + $path = $executable->display_handler->getPath(); + $split = explode('/', $path); + array_pop($split); + $path = implode('/', $split); + + $pattern = '/' . str_replace('%', '{}', $path); + if ($routes = $this->routeProvider->getRoutesByPattern($pattern)) { + foreach ($routes->all() as $name => $route) { + $local_task_key = 'views_view:' . $plugin_id . ($is_parent ? '.parent' : ''); + $local_tasks[$local_task_key]['base_route'] = $name; + // Skip after the first found route. + break; + } + } } } }