You are here

protected function RouteSubscriber::alterRoutes in RedHen CRM 8

Same name in this branch
  1. 8 src/Routing/RouteSubscriber.php \Drupal\redhen\Routing\RouteSubscriber::alterRoutes()
  2. 8 modules/redhen_connection/src/Routing/RouteSubscriber.php \Drupal\redhen_connection\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

modules/redhen_connection/src/Routing/RouteSubscriber.php, line 36

Class

RouteSubscriber
Listens to the dynamic route events.

Namespace

Drupal\redhen_connection\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  foreach (\Drupal::service('redhen_connection.connections')
    ->getAllConnectionEntityTypes() as $entity_type_id => $entity_type) {

    // If the entity didn't get a redhen_connection link template added by
    // hook_entity_types_alter(), skip it.
    if (!($path = $entity_type
      ->getLinkTemplate('redhen_connection'))) {
      continue;
    }

    // Create the "listing" route to show all the connected entities for this
    // entity.
    $route = new Route($path);
    $route
      ->addDefaults([
      '_controller' => '\\Drupal\\redhen_connection\\Controller\\RedhenConnections::list',
      '_title' => 'Connections',
    ])
      ->addRequirements([
      '_custom_access' => '\\Drupal\\redhen_connection\\Controller\\RedhenConnections::access',
    ])
      ->setOption('_admin_route', TRUE)
      ->setOption('parameters', [
      $entity_type_id => [
        'type' => 'entity:' . $entity_type_id,
      ],
    ]);
    $collection
      ->add("entity.{$entity_type_id}.redhen_connection", $route);
  }
}