You are here

class RouteSubscriber in RedHen CRM 8

Same name in this branch
  1. 8 src/Routing/RouteSubscriber.php \Drupal\redhen\Routing\RouteSubscriber
  2. 8 modules/redhen_connection/src/Routing/RouteSubscriber.php \Drupal\redhen_connection\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'
redhen_connection.services.yml in modules/redhen_connection/redhen_connection.services.yml
modules/redhen_connection/redhen_connection.services.yml
1 service uses RouteSubscriber
redhen_connection.route_subscriber in modules/redhen_connection/redhen_connection.services.yml
Drupal\redhen_connection\Routing\RouteSubscriber

File

modules/redhen_connection/src/Routing/RouteSubscriber.php, line 14

Namespace

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

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

  /**
   * Constructs a new RouteSubscriber object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_manager) {
    $this->entityTypeManager = $entity_manager;
  }

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    foreach (\Drupal::service('redhen_connection.connections')
      ->getAllConnectionEntityTypes() as $entity_type_id => $entity_type) {

      // If the entity didn't get a redhen_connection link template added by
      // hook_entity_types_alter(), skip it.
      if (!($path = $entity_type
        ->getLinkTemplate('redhen_connection'))) {
        continue;
      }

      // Create the "listing" route to show all the connected entities for this
      // entity.
      $route = new Route($path);
      $route
        ->addDefaults([
        '_controller' => '\\Drupal\\redhen_connection\\Controller\\RedhenConnections::list',
        '_title' => 'Connections',
      ])
        ->addRequirements([
        '_custom_access' => '\\Drupal\\redhen_connection\\Controller\\RedhenConnections::access',
      ])
        ->setOption('_admin_route', TRUE)
        ->setOption('parameters', [
        $entity_type_id => [
          'type' => 'entity:' . $entity_type_id,
        ],
      ]);
      $collection
        ->add("entity.{$entity_type_id}.redhen_connection", $route);
    }
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::$entityTypeManager protected property The entity type 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