You are here

class RouteSubscriber in Language Hierarchy 8

Same name and namespace in other branches
  1. 2.x src/Routing/RouteSubscriber.php \Drupal\language_hierarchy\Routing\RouteSubscriber

Listens to the dynamic route events.

Hierarchy

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

Expanded class hierarchy of RouteSubscriber

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

File

src/Routing/RouteSubscriber.php, line 13

Namespace

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

  /**
   * The mapper plugin discovery service.
   *
   * @var \Drupal\config_translation\ConfigMapperManagerInterface
   */
  protected $mapperManager;

  /**
   * Constructs a new RouteSubscriber.
   *
   * @param \Drupal\config_translation\ConfigMapperManagerInterface $mapper_manager
   *   The mapper plugin discovery service.
   */
  public function __construct(ConfigMapperManagerInterface $mapper_manager) {
    $this->mapperManager = $mapper_manager;
  }

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    $mappers = $this->mapperManager
      ->getMappers($collection);
    foreach ($mappers as $mapper) {
      $route = $collection
        ->get($mapper
        ->getOverviewRouteName());
      if ($route
        ->getDefault('_controller') === '\\Drupal\\config_translation\\Controller\\ConfigTranslationController::itemPage') {
        $route
          ->setDefault('_controller', '\\Drupal\\language_hierarchy\\Controller\\ConfigTranslationController::itemPage');
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {

    // Come after field_ui.
    $events[RoutingEvents::ALTER] = [
      'onAlterRoutes',
      -110,
    ];
    return $events;
  }

}

Members

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