class RouteSubscriber in Printer and PDF versions for Drupal 8+ 2.x
Same name and namespace in other branches
- 8 src/Routing/RouteSubscriber.php \Drupal\printable\Routing\RouteSubscriber
Defines a route subscriber to generate print route for all content entities.
Hierarchy
- class \Drupal\printable\Routing\RouteSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of RouteSubscriber
1 string reference to 'RouteSubscriber'
1 service uses RouteSubscriber
File
- src/
Routing/ RouteSubscriber.php, line 14
Namespace
Drupal\printable\RoutingView source
class RouteSubscriber implements EventSubscriberInterface {
/**
* The printable entity manager service.
*
* @var \Drupal\printable\PrintableEntityManagerInterface
*/
protected $printableEntityManager;
/**
* Constructs a printable RouteSubscriber object.
*
* @param \Drupal\printable\PrintableEntityManagerInterface $printable_entity_manager
* The printable entity manager service.
*/
public function __construct(PrintableEntityManagerInterface $printable_entity_manager) {
$this->printableEntityManager = $printable_entity_manager;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[RoutingEvents::ALTER] = 'routes';
return $events;
}
/**
* Adds a print route for each content entity.
*
* @param \Drupal\Core\Routing\RouteBuildEvent $event
* The route build event.
*/
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_callback' => 'Drupal\\printable\\Controller\\PrintableController::getTitle',
], [
'_entity_access' => 'entity.view',
'_permission' => 'view printer friendly versions',
], [
'parameters' => [
'entity' => [
'type' => 'entity:' . $entity_type,
],
],
]);
$collection
->add('printable.show_format.' . $entity_type, $route);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
protected | property | The printable entity manager service. | |
RouteSubscriber:: |
public static | function | ||
RouteSubscriber:: |
public | function | Adds a print route for each content entity. | |
RouteSubscriber:: |
public | function | Constructs a printable RouteSubscriber object. |