You are here

public function RouteSubscriber::routes in Printer and PDF versions for Drupal 8+ 8

Same name and namespace in other branches
  1. 2.x src/Routing/RouteSubscriber.php \Drupal\printable\Routing\RouteSubscriber::routes()

Adds a print route for each content entity.

Parameters

\Drupal\Core\Routing\RouteBuildEvent $event: The route build event.

File

src/Routing/RouteSubscriber.php, line 47

Class

RouteSubscriber
Defines a route subscriber to generate print route for all content entities.

Namespace

Drupal\printable\Routing

Code

public function routes(RouteBuildEvent $event) {
  $collection = $event
    ->getRouteCollection();
  foreach ($this->printableEntityManager
    ->getPrintableEntities() as $entity_type => $entity_definition) {
    $route = new Route("{$entity_type}/{entity}/printable/{printable_format}", [
      '_controller' => 'Drupal\\printable\\Controller\\PrintableController::showFormat',
      '_title' => 'Printable',
    ], [
      '_entity_access' => 'entity.view',
      '_permission' => 'view printer friendly versions',
    ], [
      'parameters' => [
        'entity' => [
          'type' => 'entity:' . $entity_type,
        ],
      ],
    ]);
    $collection
      ->add('printable.show_format.' . $entity_type, $route);
  }
}