You are here

public function ScheduledTransitionsRouteProvider::getRoutes in Scheduled Transitions 8

Same name and namespace in other branches
  1. 2.x src/Routing/ScheduledTransitionsRouteProvider.php \Drupal\scheduled_transitions\Routing\ScheduledTransitionsRouteProvider::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/ScheduledTransitionsRouteProvider.php, line 42

Class

ScheduledTransitionsRouteProvider
Route provider for host entities of Scheduled Transitions.

Namespace

Drupal\scheduled_transitions\Routing

Code

public function getRoutes(EntityTypeInterface $entity_type) {
  $collection = new RouteCollection();
  $entityTypeId = $entity_type
    ->id();
  if ($entity_type
    ->hasLinkTemplate(static::LINK_TEMPLATE)) {
    $path = $entity_type
      ->getLinkTemplate('canonical') . static::CANONICAL_PATH_SUFFIX;
    $route = (new Route($path))
      ->addDefaults([
      '_title' => 'Scheduled transitions',
      '_entity_form' => $entityTypeId . '.' . static::FORM,
    ])
      ->setRequirement('_entity_access', $entityTypeId . '.' . Permissions::ENTITY_OPERATION_VIEW_TRANSITIONS)
      ->setRequirement(AccessCheck::ACCESS_CHECK_ID, 'TRUE')
      ->setOption('_admin_route', TRUE)
      ->setOption(static::ROUTE_ENTITY_TYPE, $entityTypeId)
      ->setOption('parameters', [
      $entityTypeId => [
        'type' => 'entity:' . $entityTypeId,
      ],
    ]);
    $collection
      ->add(static::getScheduledTransitionRouteName($entity_type), $route);
  }
  if ($entity_type
    ->hasLinkTemplate(static::LINK_TEMPLATE_ADD)) {
    $path = $entity_type
      ->getLinkTemplate('canonical') . static::CANONICAL_PATH_SUFFIX_ADD;
    $route = (new Route($path))
      ->addDefaults([
      '_title' => 'Add scheduled transition',
      '_entity_form' => $entityTypeId . '.' . static::FORM_ADD,
    ])
      ->setRequirement('_entity_access', $entityTypeId . '.' . Permissions::ENTITY_OPERATION_ADD_TRANSITION)
      ->setRequirement(AccessCheck::ACCESS_CHECK_ID, 'TRUE')
      ->setOption('_admin_route', TRUE)
      ->setOption(static::ROUTE_ENTITY_TYPE, $entityTypeId)
      ->setOption('parameters', [
      $entityTypeId => [
        'type' => 'entity:' . $entityTypeId,
      ],
    ]);
    $collection
      ->add(static::getScheduledTransitionAddRouteName($entity_type), $route);
  }
  return $collection;
}