public LocalTaskManager::getTasksBuild($current_route_name, RefinableCacheableDependencyInterface &$cacheability)
Gets the render array for all local tasks.
Parameters
string $current_route_name: The route for which to make renderable local tasks.
\Drupal\Core\Cache\RefinableCacheableDependencyInterface $cacheability: The cacheability metadata for the local tasks.
Return value
array A render array as expected by menu-local-tasks.html.twig.
Overrides LocalTaskManagerInterface::getTasksBuild
File
- core/lib/Drupal/Core/Menu/LocalTaskManager.php, line 289
Class
- LocalTaskManager
- Provides the default local task manager using YML as primary definition.
Namespace
Drupal\Core\Menu
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | public function getTasksBuild( $current_route_name , RefinableCacheableDependencyInterface & $cacheability ) { $tree = $this ->getLocalTasksForRoute( $current_route_name ); $build = array (); // Collect all route names. $route_names = array (); foreach ( $tree as $instances ) { foreach ( $instances as $child ) { $route_names [] = $child ->getRouteName(); } } // Pre-fetch all routes involved in the tree. This reduces the number // of SQL queries that would otherwise be triggered by the access manager. if ( $route_names ) { $this ->routeProvider->getRoutesByNames( $route_names ); } foreach ( $tree as $level => $instances ) { /** @var $instances \Drupal\Core\Menu\LocalTaskInterface[] */ foreach ( $instances as $plugin_id => $child ) { $route_name = $child ->getRouteName(); $route_parameters = $child ->getRouteParameters( $this ->routeMatch); // Given that the active flag depends on the route we have to add the // route cache context. $cacheability ->addCacheContexts([ 'route' ]); $active = $this ->isRouteActive( $current_route_name , $route_name , $route_parameters ); // The plugin may have been set active in getLocalTasksForRoute() if // one of its child tabs is the active tab. $active = $active || $child ->getActive(); // @todo It might make sense to use link render elements instead. $link = [ 'title' => $this ->getTitle( $child ), 'url' => Url::fromRoute( $route_name , $route_parameters ), 'localized_options' => $child ->getOptions( $this ->routeMatch), ]; $access = $this ->accessManager->checkNamedRoute( $route_name , $route_parameters , $this ->account, TRUE); $build [ $level ][ $plugin_id ] = [ '#theme' => 'menu_local_task' , '#link' => $link , '#active' => $active , '#weight' => $child ->getWeight(), '#access' => $access , ]; $cacheability ->addCacheableDependency( $access )->addCacheableDependency( $child ); } } return $build ; } |
Please login to continue.