function LocalTaskManager::getTasksBuild
Same name in other branches
- 9 core/lib/Drupal/Core/Menu/LocalTaskManager.php \Drupal\Core\Menu\LocalTaskManager::getTasksBuild()
- 8.9.x core/lib/Drupal/Core/Menu/LocalTaskManager.php \Drupal\Core\Menu\LocalTaskManager::getTasksBuild()
- 11.x core/lib/Drupal/Core/Menu/LocalTaskManager.php \Drupal\Core\Menu\LocalTaskManager::getTasksBuild()
1 call to LocalTaskManager::getTasksBuild()
- LocalTaskManager::getLocalTasks in core/
lib/ Drupal/ Core/ Menu/ LocalTaskManager.php
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\MenuCode
public function getTasksBuild($current_route_name, RefinableCacheableDependencyInterface &$cacheability) {
$tree = $this->getLocalTasksForRoute($current_route_name);
$build = [];
// Collect all route names.
$route_names = [];
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 \Drupal\Core\Menu\LocalTaskInterface[] $instances */
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.