3 namespace Drupal\entity\Menu;
5 use Drupal\Core\Entity\EntityTypeInterface;
8 * Provides a action link to the add page or add form on the collection.
10 class EntityCollectionLocalActionProvider implements EntityLocalActionProviderInterface {
15 public function buildLocalActions(EntityTypeInterface $entity_type) {
17 if ($entity_type->hasLinkTemplate('collection')) {
18 $entity_type_id = $entity_type->id();
20 if ($entity_type->hasLinkTemplate('add-page')) {
21 $route_name = "entity.$entity_type_id.add_page";
23 elseif ($entity_type->hasLinkTemplate('add-form')) {
24 $route_name = "entity.$entity_type_id.add_form";
27 if (isset($route_name)) {
28 $actions[$route_name] = [
29 // The title is translated at runtime by EntityAddLocalAction.
30 /* @see \Drupal\entity\Menu\EntityAddLocalAction::getTitle() */
31 'title' => 'Add ' . $entity_type->getSingularLabel(),
32 'route_name' => $route_name,
34 // Redirect back to the collection after form submission.
36 'destination' => $entity_type->getLinkTemplate('collection'),
39 'appears_on' => ["entity.$entity_type_id.collection"],
40 'class' => EntityAddLocalAction::class,