You are here

class RouteSubscriber in Token 8

Subscriber for Devel routes.

Hierarchy

Expanded class hierarchy of RouteSubscriber

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

File

src/Routing/RouteSubscriber.php, line 15

Namespace

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

  /**
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;
  public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler) {
    $this->entityTypeManager = $entity_type_manager;
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type_id => $entity_type) {
      if ($devel_render = $entity_type
        ->getLinkTemplate('token-devel')) {
        $options = [
          '_admin_route' => TRUE,
          '_token_entity_type_id' => $entity_type_id,
          'parameters' => [
            $entity_type_id => [
              'type' => 'entity:' . $entity_type_id,
            ],
          ],
        ];
        $route = new Route($devel_render, [
          '_controller' => '\\Drupal\\token\\Controller\\TokenDevelController::entityTokens',
          '_title' => 'Devel Tokens',
        ], [
          '_permission' => 'access devel information',
          '_module_dependencies' => 'devel',
        ], $options);
        $collection
          ->add("entity.{$entity_type_id}.token_devel", $route);
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events = parent::getSubscribedEvents();
    $events[RoutingEvents::ALTER] = array(
      'onAlterRoutes',
      100,
    );
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::$entityTypeManager protected property
RouteSubscriber::$moduleHandler protected property
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
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1