You are here

public function RouteSubscriber::alterRoutes in Flexiform 8

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

contrib/wizard/src/Routing/RouteSubscriber.php, line 35

Class

RouteSubscriber
Subscriber for wizard routes.

Namespace

Drupal\flexiform_wizard\Routing

Code

public function alterRoutes(RouteCollection $collection) {
  foreach ($this->entityTypeManager
    ->getStorage('flexiform_wizard')
    ->loadMultiple() as $wizard_id => $wizard) {
    $options = [];
    foreach ($wizard
      ->get('parameters') as $param_name => $param_info) {
      $options['parameters'][$param_name] = [
        'type' => 'entity:' . $param_info['entity_type'],
      ];
    }
    $options['parameters']['wizard'] = [
      'type' => 'entity:flexiform_wizard',
    ];
    $defaults = [
      '_wizard' => '\\Drupal\\flexiform_wizard\\Wizard\\DefaultWizard',
      '_title' => 'Wizard',
      'wizard' => $wizard_id,
    ];
    $route = new Route($wizard
      ->get('path'), $defaults, [
      '_access' => 'TRUE',
    ], $options);
    $collection
      ->add("flexiform_wizard.{$wizard_id}", $route);
    $route = new Route($wizard
      ->get('path') . '/{step}', $defaults, [
      '_access' => 'TRUE',
    ], $options);
    $collection
      ->add("flexiform_wizard.{$wizard_id}.step", $route);
  }
}