You are here

class RouteSubscriber in Display Suite 8.2

Same name in this branch
  1. 8.2 src/Routing/RouteSubscriber.php \Drupal\ds\Routing\RouteSubscriber
  2. 8.2 modules/ds_devel/src/Routing/RouteSubscriber.php \Drupal\ds_devel\Routing\RouteSubscriber
  3. 8.2 modules/ds_extras/src/EventSubscriber/RouteSubscriber.php \Drupal\ds_extras\EventSubscriber\RouteSubscriber
Same name and namespace in other branches
  1. 8.4 src/Routing/RouteSubscriber.php \Drupal\ds\Routing\RouteSubscriber
  2. 8.3 src/Routing/RouteSubscriber.php \Drupal\ds\Routing\RouteSubscriber

Subscriber for Devel routes.

Hierarchy

Expanded class hierarchy of RouteSubscriber

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

File

src/Routing/RouteSubscriber.php, line 14

Namespace

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

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

  /**
   * Constructs a new 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}
   */
  protected function alterRoutes(RouteCollection $collection) {
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type_id => $entity_type) {
      $base_table = $entity_type
        ->getBaseTable();
      if ($entity_type
        ->get('field_ui_base_route') && !empty($base_table)) {
        if ($display = $entity_type
          ->getLinkTemplate('display')) {
          $route = new Route($display, array(
            '_controller' => '\\Drupal\\ds\\Controller\\DsController::contextualTab',
            '_title' => 'Manage display',
            'entity_type_id' => $entity_type_id,
          ), array(
            '_field_ui_view_mode_access' => 'administer ' . $entity_type_id . ' display',
          ), array(
            '_admin_route' => TRUE,
            '_ds_entity_type_id' => $entity_type_id,
            'parameters' => array(
              $entity_type_id => array(
                'type' => 'entity:' . $entity_type_id,
              ),
            ),
          ));
          $collection
            ->add("entity.{$entity_type_id}.display", $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 The entity manager 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 object.
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1