You are here

class RouteSubscriber in Flexiform 8

Same name in this branch
  1. 8 src/Routing/RouteSubscriber.php \Drupal\flexiform\Routing\RouteSubscriber
  2. 8 contrib/wizard/src/Routing/RouteSubscriber.php \Drupal\flexiform_wizard\Routing\RouteSubscriber

Subscriber for wizard routes.

Hierarchy

  • class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RouteSubscriber

1 string reference to 'RouteSubscriber'
flexiform_wizard.services.yml in contrib/wizard/flexiform_wizard.services.yml
contrib/wizard/flexiform_wizard.services.yml
1 service uses RouteSubscriber
flexiform_wizard.subscriber in contrib/wizard/flexiform_wizard.services.yml
Drupal\flexiform_wizard\Routing\RouteSubscriber

File

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

Namespace

Drupal\flexiform_wizard\Routing
View source
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a RouteSubscriber object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  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);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::$entityTypeManager protected property The entity type manager.
RouteSubscriber::alterRoutes public function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
RouteSubscriber::__construct public function Constructs a RouteSubscriber object.
RouteSubscriberBase::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. 5
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1