You are here

class RouteSubscriber in Page Manager 8.4

Same name and namespace in other branches
  1. 8 tests/modules/page_manager_routing_test/src/Routing/RouteSubscriber.php \Drupal\page_manager_routing_test\Routing\RouteSubscriber

Route subscriber for Page Manager Routing Test.

Hierarchy

  • class \Drupal\page_manager_routing_test\Routing\RouteSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RouteSubscriber

1 string reference to 'RouteSubscriber'
page_manager_routing_test.services.yml in tests/modules/page_manager_routing_test/page_manager_routing_test.services.yml
tests/modules/page_manager_routing_test/page_manager_routing_test.services.yml
1 service uses RouteSubscriber
page_manager_routing_test.subscriber in tests/modules/page_manager_routing_test/page_manager_routing_test.services.yml
Drupal\page_manager_routing_test\Routing\RouteSubscriber

File

tests/modules/page_manager_routing_test/src/Routing/RouteSubscriber.php, line 13

Namespace

Drupal\page_manager_routing_test\Routing
View source
class RouteSubscriber implements EventSubscriberInterface {

  /**
   * Alters the existing route collection.
   *
   * @param \Drupal\Core\Routing\RouteBuildEvent $event
   *   The route build event.
   */
  public function beforePageManagerRoutes(RouteBuildEvent $event) {
    $collection = $event
      ->getRouteCollection();
    $route = new Route('/entity_test/{entity_test}', [], [
      '_access' => 'TRUE',
    ]);
    $route
      ->setRequirement('_format', 'xml');
    $collection
      ->add('entity.entity_test.canonical.xml', $route);
  }

  /**
   * Alters the existing route collection.
   *
   * @param \Drupal\Core\Routing\RouteBuildEvent $event
   *   The route build event.
   */
  public function afterPageManagerRoutes(RouteBuildEvent $event) {
    $collection = $event
      ->getRouteCollection();
    if ($original_route = $collection
      ->get('entity.entity_test.canonical')) {
      $route = new Route($original_route
        ->getPath(), $original_route
        ->getDefaults(), $original_route
        ->getRequirements(), $original_route
        ->getOptions());
      $route
        ->setRequirement('_format', 'json');
      $collection
        ->add('entity.entity_test.canonical.json', $route);
    }
  }

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

    // Run before PageManagerRoutes.
    $events[RoutingEvents::ALTER][] = [
      'beforePageManagerRoutes',
      -155,
    ];

    // Run after PageManagerRoutes.
    $events[RoutingEvents::ALTER][] = [
      'afterPageManagerRoutes',
      -165,
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::afterPageManagerRoutes public function Alters the existing route collection.
RouteSubscriber::beforePageManagerRoutes public function Alters the existing route collection.
RouteSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.