You are here

class RouteSubscriber in RNG - Events and Registrations 8.2

Same name in this branch
  1. 8.2 src/Routing/RouteSubscriber.php \Drupal\rng\Routing\RouteSubscriber
  2. 8.2 rng_debug/src/Routing/RouteSubscriber.php \Drupal\rng_debug\Routing\RouteSubscriber
Same name and namespace in other branches
  1. 8 rng_debug/src/Routing/RouteSubscriber.php \Drupal\rng_debug\Routing\RouteSubscriber
  2. 3.x rng_debug/src/Routing/RouteSubscriber.php \Drupal\rng_debug\Routing\RouteSubscriber

Dynamic routes.

Hierarchy

Expanded class hierarchy of RouteSubscriber

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

File

rng_debug/src/Routing/RouteSubscriber.php, line 14

Namespace

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

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * The RNG event manager.
   *
   * @var \Drupal\rng\EventManagerInterface
   */
  protected $eventManager;

  /**
   * Constructs a RouteSubscriber object.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   * @param \Drupal\rng\EventManagerInterface $event_manager
   *   The RNG event manager.
   */
  public function __construct(EntityManagerInterface $entity_manager, EventManagerInterface $event_manager) {
    $this->entityManager = $entity_manager;
    $this->eventManager = $event_manager;
  }

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    $event_types = $this->eventManager
      ->getEventTypes();
    foreach (array_keys($event_types) as $entity_type) {
      $definition = $this->entityManager
        ->getDefinition($entity_type);
      if ($canonical_path = $definition
        ->getLinkTemplate('canonical')) {
        $manage_requirements = [
          '_entity_access' => $entity_type . '.manage event',
          '_entity_is_event' => 'TRUE',
          '_permission' => 'debug rng',
        ];
        $options = [];
        $options['parameters'][$entity_type]['type'] = 'entity:' . $entity_type;

        // Rules.
        $route = new Route($canonical_path . '/event/rules', [
          '_controller' => '\\Drupal\\rng_debug\\Controller\\DebugController::listing',
          '_title' => 'Rules',
          'event' => $entity_type,
        ], $manage_requirements, $options);
        $collection
          ->add("rng.event.{$entity_type}.rules", $route);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::$entityManager protected property The entity type manager.
RouteSubscriber::$eventManager protected property The RNG event manager.
RouteSubscriber::alterRoutes protected function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
RouteSubscriber::__construct public function Constructs a RouteSubscriber object.
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