NodeRouteProvider::getRoutes

public NodeRouteProvider::getRoutes(EntityTypeInterface $entity_type)

Provides routes for entities.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type

Return value

\Symfony\Component\Routing\RouteCollection|\Symfony\Component\Routing\Route[] Returns a route collection or an array of routes keyed by name, like route_callbacks inside 'routing.yml' files.

Overrides EntityRouteProviderInterface::getRoutes

File

core/modules/node/src/Entity/NodeRouteProvider.php, line 18

Class

NodeRouteProvider
Provides routes for nodes.

Namespace

Drupal\node\Entity

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
public function getRoutes(EntityTypeInterface $entity_type) {
  $route_collection = new RouteCollection();
  $route = (new Route('/node/{node}'))
    ->addDefaults([
      '_controller' => '\Drupal\node\Controller\NodeViewController::view',
      '_title_callback' => '\Drupal\node\Controller\NodeViewController::title',
    ])
    ->setRequirement('node', '\d+')
    ->setRequirement('_entity_access', 'node.view');
  $route_collection->add('entity.node.canonical', $route);
 
  $route = (new Route('/node/{node}/delete'))
    ->addDefaults([
      '_entity_form' => 'node.delete',
      '_title' => 'Delete',
    ])
    ->setRequirement('node', '\d+')
    ->setRequirement('_entity_access', 'node.delete')
    ->setOption('_node_operation_route', TRUE);
  $route_collection->add('entity.node.delete_form', $route);
 
  $route = (new Route('/node/{node}/edit'))
    ->setDefault('_entity_form', 'node.edit')
    ->setRequirement('_entity_access', 'node.update')
    ->setRequirement('node', '\d+')
    ->setOption('_node_operation_route', TRUE);
  $route_collection->add('entity.node.edit_form', $route);
 
  return $route_collection;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.