You are here

WebformShareRouteSubscriber.php in Webform 8.5

Same filename and directory in other branches
  1. 6.x modules/webform_share/src/Routing/WebformShareRouteSubscriber.php

File

modules/webform_share/src/Routing/WebformShareRouteSubscriber.php
View source
<?php

namespace Drupal\webform_share\Routing;

use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

/**
 * Remove webform share routes.
 */
class WebformShareRouteSubscriber extends RouteSubscriberBase {

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Constructs a WebformShareRouteSubscriber object.
   *
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   */
  public function __construct(ModuleHandlerInterface $module_handler) {
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    if (!$this->moduleHandler
      ->moduleExists('webform_node')) {
      $collection
        ->remove('entity.node.webform.share_embed');
      $collection
        ->remove('entity.node.webform.share_preview');
      $collection
        ->remove('entity.node.webform.share_test');
    }
  }

}

Classes

Namesort descending Description
WebformShareRouteSubscriber Remove webform share routes.