You are here

protected function RouteSubscriber::alterRoutes in Salesforce Suite 8.3

Alters existing routes for a specific collection.

Parameters

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

Overrides RouteSubscriberBase::alterRoutes

File

modules/salesforce_mapping/src/Routing/RouteSubscriber.php, line 42

Class

RouteSubscriber
Listens to the dynamic route events.

Namespace

Drupal\salesforce_mapping\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {

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

    // Create the "listing" route to show all the mapped objects for this
    // entity.
    $route = new Route($path);
    $route
      ->addDefaults([
      '_controller' => "\\Drupal\\salesforce_mapping\\Controller\\MappedObjectController::listing",
      '_title' => "Salesforce mapped objects",
    ])
      ->addRequirements([
      '_custom_access' => '\\Drupal\\salesforce_mapping\\Controller\\MappedObjectController::access',
    ])
      ->setOption('_admin_route', TRUE)
      ->setOption('_salesforce_entity_type_id', $entity_type_id)
      ->setOption('parameters', [
      $entity_type_id => [
        'type' => 'entity:' . $entity_type_id,
      ],
    ]);
    $collection
      ->add("entity.{$entity_type_id}.salesforce", $route);
  }
}