You are here

class RouteSubscriber in Webform Views Integration 8.5

Alter the routes in order to allow multiple views on the same route.

Alter the routes so '{webform}' parameter is present and defaults to the corresponding webform for all views that are related to webform submissions.

Hierarchy

Expanded class hierarchy of RouteSubscriber

1 string reference to 'RouteSubscriber'
webform_views.services.yml in ./webform_views.services.yml
webform_views.services.yml
1 service uses RouteSubscriber
webform_views.route_subscriber in ./webform_views.services.yml
Drupal\webform_views\Routing\RouteSubscriber

File

src/Routing/RouteSubscriber.php, line 16

Namespace

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

  /**
   * @var StateInterface
   */
  protected $state;

  /**
   * @var EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * RouteSubscriber constructor.
   */
  public function __construct(StateInterface $state, EntityTypeManagerInterface $entity_type_manager) {
    $this->state = $state;
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    $view_route_names = $this->state
      ->get('views.view_route_names');
    foreach (webform_views_applicable_views() as $trio) {
      list($view_id, $display_id, $path) = $trio;
      $route_name = $view_route_names[$view_id . '.' . $display_id];
      if (($route = $collection
        ->get($route_name)) && ($webform_id = webform_views_webform_id_from_path($path))) {
        $route
          ->setPath($route
          ->getPath() . '/{webform}');
        $route
          ->setDefault('webform', $webform_id);
        $options = $route
          ->getOptions();
        $options['parameters']['webform']['type'] = 'entity:webform';
        $route
          ->setOptions($options);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::$entityTypeManager protected property
RouteSubscriber::$state protected property
RouteSubscriber::alterRoutes protected function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
RouteSubscriber::__construct public function RouteSubscriber constructor.
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