diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index 6aa0ffd..8b36395 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -208,14 +208,7 @@ public function getLocalTasksForRoute($route_name) { $children = $cache->data['children']; } else { - $definitions = $this->getDefinitions(); - // We build the hierarchy by finding all tabs that should - // appear on the current route. - list($definitions, $base_routes, $parents) = $this->calculateHierarchyTaskInformation($route_name, $definitions); - $children = array(); - if ($base_routes) { - $children = $this->findBaseRouteChildren($definitions, $base_routes, $parents); - } + list ($base_routes, $parents, $children) = $this->calculateLocalTasksInformationForRoute($route_name); $this->setLocalTasksCache($route_name, $base_routes, $parents, $children); } @@ -225,6 +218,28 @@ public function getLocalTasksForRoute($route_name) { } /** + * Find all local tasks that appear on a named route. + * + * @param string $route_name + * The route for which to find local tasks. + * + * @return array + * An array with the matching base routes, parents and children. + */ + protected function calculateLocalTasksInformationForRoute($route_name) { + $definitions = $this->getDefinitions(); + // We build the hierarchy by finding all tabs that should + // appear on the current route. + list($definitions, $base_routes, $parents) = $this->calculateHierarchyTaskInformation($route_name, $definitions); + $children = array(); + if ($base_routes) { + $children = $this->findBaseRouteChildren($definitions, $base_routes, $parents); + } + + return [$base_routes, $parents, $children]; + } + + /** * {@inheritdoc} */ public function getTasksBuild($current_route_name, RefinableCacheableDependencyInterface &$cacheability) { @@ -368,13 +383,15 @@ protected function isRouteActive($current_route_name, $route_name, $route_parame * An array of plugin information keyed by parent ID and plugin ID. */ protected function findBaseRouteChildren(array $definitions, array $base_routes, array $parents) { + $active_local_task_definitions = array_filter($definitions, function ($task_info) { + return !empty($base_routes[$task_info['base_route']]) && (empty($task_info['parent_id']) || !empty($parents[$task_info['parent_id']])); + }); + $children = []; - foreach ($definitions as $plugin_id => $task_info) { - if (!empty($base_routes[$task_info['base_route']]) && (empty($task_info['parent_id']) || !empty($parents[$task_info['parent_id']]))) { - // Concat '> ' with root ID for the parent of top-level tabs. - $parent = empty($task_info['parent_id']) ? '> ' . $task_info['base_route'] : $task_info['parent_id']; - $children[$parent][$plugin_id] = $task_info; - } + foreach ($active_local_task_definitions as $plugin_id => $task_info) { + // Concat '> ' with root ID for the parent of top-level tabs. + $parent = empty($task_info['parent_id']) ? '> ' . $task_info['base_route'] : $task_info['parent_id']; + $children[$parent][$plugin_id] = $task_info; } return $children; }