You are here

public function RouteSubscriber::routes in Forms Steps 8

Returns a set of route objects.

Return value

\Symfony\Component\Routing\RouteCollection A route collection.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

src/EventSubscriber/RouteSubscriber.php, line 97

Class

RouteSubscriber
Builds up the routes of all forms steps. (based on views RouteSubscriber)

Namespace

Drupal\forms_steps\EventSubscriber

Code

public function routes() {
  $collection = new RouteCollection();
  $entity_ids = $this->entityTypeManager
    ->getStorage(FormsSteps::ENTITY_TYPE)
    ->getQuery()
    ->execute();

  // Loads of all forms steps.
  $forms_steps = $this->entityTypeManager
    ->getStorage(FormsSteps::ENTITY_TYPE)
    ->loadMultiple($entity_ids);
  $route_options = [];
  if ($this->configFactory
    ->get('node.settings')
    ->get('use_admin_theme')) {
    $route_options['_admin_route'] = TRUE;
  }

  /** @var \Drupal\forms_steps\Entity\FormsSteps $form_steps */
  foreach ($forms_steps as $form_steps) {
    foreach ($form_steps
      ->getSteps() as $step) {
      $route = new Route($step
        ->url() . '/{instance_id}', [
        '_controller' => '\\Drupal\\forms_steps\\Controller\\FormsStepsController::step',
        '_title' => $step
          ->label(),
        'forms_steps' => $form_steps
          ->id(),
        'step' => $step
          ->id(),
        'instance_id' => '',
      ], [
        '_permission' => 'access content',
        'instance_id' => '^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$',
      ], $route_options);
      $collection
        ->add('forms_steps.' . $form_steps
        ->id() . '.' . $step
        ->id(), $route);
    }
  }
  return $collection;
}