You are here

protected function RouteSubscriber::alterRoutes in RNG - Events and Registrations 3.x

Same name in this branch
  1. 3.x src/Routing/RouteSubscriber.php \Drupal\rng\Routing\RouteSubscriber::alterRoutes()
  2. 3.x rng_debug/src/Routing/RouteSubscriber.php \Drupal\rng_debug\Routing\RouteSubscriber::alterRoutes()
Same name and namespace in other branches
  1. 8.2 rng_debug/src/Routing/RouteSubscriber.php \Drupal\rng_debug\Routing\RouteSubscriber::alterRoutes()
  2. 8 rng_debug/src/Routing/RouteSubscriber.php \Drupal\rng_debug\Routing\RouteSubscriber::alterRoutes()

Alters existing routes for a specific collection.

Parameters

\Symfony\Component\Routing\RouteCollection $collection: The route collection for adding routes.

Overrides RouteSubscriberBase::alterRoutes

File

rng_debug/src/Routing/RouteSubscriber.php, line 46

Class

RouteSubscriber
Dynamic routes.

Namespace

Drupal\rng_debug\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  $event_types = $this->eventManager
    ->getEventTypes();
  foreach (array_keys($event_types) as $entity_type) {
    $definition = $this->entityTypeManager
      ->getDefinition($entity_type);
    if ($canonical_path = $definition
      ->getLinkTemplate('canonical')) {
      $manage_requirements = [
        '_entity_access' => $entity_type . '.manage event',
        '_entity_is_event' => 'TRUE',
        '_permission' => 'debug rng',
      ];
      $options = [];
      $options['parameters'][$entity_type]['type'] = 'entity:' . $entity_type;

      // Rules.
      $route = new Route($canonical_path . '/event/rules', [
        '_controller' => '\\Drupal\\rng_debug\\Controller\\DebugController::listing',
        '_title' => 'Rules',
        'event' => $entity_type,
      ], $manage_requirements, $options);
      $collection
        ->add("rng.event.{$entity_type}.rules", $route);
    }
  }
}