You are here

public function EntityHierarchyRouteProvider::getRoutes in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 src/Routing/EntityHierarchyRouteProvider.php \Drupal\entity_hierarchy\Routing\EntityHierarchyRouteProvider::getRoutes()

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

src/Routing/EntityHierarchyRouteProvider.php, line 68

Class

EntityHierarchyRouteProvider
Defines a class for providing route definitions for hierarchy entities.

Namespace

Drupal\entity_hierarchy\Routing

Code

public function getRoutes(EntityTypeInterface $entity_type) {
  $collection = new RouteCollection();
  if ($entity_type
    ->hasLinkTemplate('entity_hierarchy_reorder')) {
    $entity_type_id = $entity_type
      ->id();
    $route = new Route($entity_type
      ->getLinkTemplate('latest-version'));
    $route
      ->setPath($entity_type
      ->getLinkTemplate('canonical') . '/children')
      ->addDefaults([
      '_title' => 'Reorder children',
      '_entity_form' => "{$entity_type_id}.entity_hierarchy_reorder",
    ])
      ->setRequirement('_entity_access', "{$entity_type_id}.view")
      ->setRequirement('_permission', 'reorder entity_hierarchy children')
      ->setRequirement(self::ENTITY_HIERARCHY_HAS_FIELD, 'TRUE')
      ->setOption(self::ENTITY_HIERARCHY_ENTITY_TYPE, $entity_type_id)
      ->setOption('_admin_route', TRUE)
      ->setOption('parameters', [
      $entity_type_id => [
        'type' => 'entity:' . $entity_type_id,
        'load_latest_revision' => FALSE,
      ],
    ]);
    $collection
      ->add("entity.{$entity_type_id}.entity_hierarchy_reorder", $route);
  }
  return $collection;
}