You are here

protected function EnhanceEntityRouteSubscriber::alterRoutes in Form mode manager 8.2

Add form mode manager requirements to add more access granularity.

Overrides RouteSubscriberBase::alterRoutes

File

src/Routing/EventSubscriber/EnhanceEntityRouteSubscriber.php, line 84

Class

EnhanceEntityRouteSubscriber
Listens to the dynamic route event and enhance existing routes.

Namespace

Drupal\form_mode_manager\Routing\EventSubscriber

Code

protected function alterRoutes(RouteCollection $collection) {
  $entity_type_ids = array_keys($this->formModeManager
    ->getAllFormModesDefinitions());
  $this->routeCollection = $collection;
  foreach ($entity_type_ids as $entity_type_id) {
    $this->entityDefinition = $this->entityTypeManager
      ->getDefinition($entity_type_id);
    $this->entityRoutingDefinition = $this->entityRoutingMap
      ->createInstance($entity_type_id, [
      'entityTypeId' => $entity_type_id,
    ]);
    $this
      ->enhanceDefaultEntityRoute('add_form');
    $this
      ->enhanceDefaultEntityRoute('edit_form');

    // This operation doesn't exist for unbundled entities.
    if (!empty($this->entityDefinition
      ->getKey('bundle'))) {
      $this
        ->enhanceDefaultEntityRoute('add_page');
    }
  }
}