public function DefaultEntityLocalTaskProvider::buildLocalTasks in Entity API 8
Builds local tasks for the given entity type.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type.
Return value
array[] An array of local task definitions.
Overrides EntityLocalTaskProviderInterface::buildLocalTasks
File
- src/
Menu/ DefaultEntityLocalTaskProvider.php, line 40
Class
- DefaultEntityLocalTaskProvider
- Provides a set of tasks to view, edit and duplicate an entity.
Namespace
Drupal\entity\MenuCode
public function buildLocalTasks(EntityTypeInterface $entity_type) {
// Note: delete-form was intentionally omitted, to match core. See #1834002.
$link_templates = [];
foreach ([
'canonical',
'edit-form',
'duplicate-form',
'version-history',
] as $rel) {
if ($entity_type
->hasLinkTemplate($rel)) {
$link_templates[] = str_replace('-', '_', $rel);
}
}
$tasks = [];
if (count($link_templates) > 1) {
$entity_type_id = $entity_type
->id();
$base = reset($link_templates);
$titles = [
'canonical' => $this
->t('View'),
'edit_form' => $this
->t('Edit'),
'duplicate_form' => $this
->t('Duplicate'),
'version_history' => $this
->t('Revisions'),
];
$weight = 0;
foreach ($link_templates as $rel) {
$route_name = "entity.{$entity_type_id}.{$rel}";
$tasks[$route_name] = [
'title' => $titles[$rel],
'route_name' => $route_name,
'base_route' => "entity.{$entity_type_id}.{$base}",
'weight' => $weight,
];
$weight += 10;
}
}
return $tasks;
}