annotate core/lib/Drupal/Core/EventSubscriber/ParamConverterSubscriber.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Core\EventSubscriber;
Chris@0 4
Chris@0 5 use Drupal\Core\ParamConverter\ParamConverterManagerInterface;
Chris@0 6 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Chris@0 7 use Drupal\Core\Routing\RoutingEvents;
Chris@0 8 use Drupal\Core\Routing\RouteBuildEvent;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Event subscriber for registering parameter converters with routes.
Chris@0 12 */
Chris@0 13 class ParamConverterSubscriber implements EventSubscriberInterface {
Chris@0 14
Chris@0 15 /**
Chris@0 16 * The parameter converter manager.
Chris@0 17 *
Chris@0 18 * @var \Drupal\Core\ParamConverter\ParamConverterManagerInterface
Chris@0 19 */
Chris@0 20 protected $paramConverterManager;
Chris@0 21
Chris@0 22 /**
Chris@0 23 * Constructs a new ParamConverterSubscriber.
Chris@0 24 *
Chris@0 25 * @param \Drupal\Core\ParamConverter\ParamConverterManagerInterface $param_converter_manager
Chris@0 26 * The parameter converter manager that will be responsible for upcasting
Chris@0 27 * request attributes.
Chris@0 28 */
Chris@0 29 public function __construct(ParamConverterManagerInterface $param_converter_manager) {
Chris@0 30 $this->paramConverterManager = $param_converter_manager;
Chris@0 31 }
Chris@0 32
Chris@0 33 /**
Chris@0 34 * Applies parameter converters to route parameters.
Chris@0 35 *
Chris@0 36 * @param \Drupal\Core\Routing\RouteBuildEvent $event
Chris@0 37 * The event to process.
Chris@0 38 */
Chris@0 39 public function onRoutingRouteAlterSetParameterConverters(RouteBuildEvent $event) {
Chris@0 40 $this->paramConverterManager->setRouteParameterConverters($event->getRouteCollection());
Chris@0 41 }
Chris@0 42
Chris@0 43 /**
Chris@0 44 * {@inheritdoc}
Chris@0 45 */
Chris@0 46 public static function getSubscribedEvents() {
Chris@0 47 // Run after \Drupal\system\EventSubscriber\AdminRouteSubscriber.
Chris@0 48 $events[RoutingEvents::ALTER][] = ['onRoutingRouteAlterSetParameterConverters', -220];
Chris@0 49 return $events;
Chris@0 50 }
Chris@0 51
Chris@0 52 }