Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / lib / Drupal / Core / EventSubscriber / EntityRouteAlterSubscriber.php
1 <?php
2
3 namespace Drupal\Core\EventSubscriber;
4
5 use Drupal\Core\Entity\EntityResolverManager;
6 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7 use Drupal\Core\Routing\RoutingEvents;
8 use Drupal\Core\Routing\RouteBuildEvent;
9
10 /**
11  * Registers the 'type' of route parameter names that match an entity type.
12  *
13  * @todo Matching on parameter *name* is not ideal, because it breaks
14  *   encapsulation: parameter names are local to the controller and route, and
15  *   controllers and routes can't be expected to know what all possible entity
16  *   types might exist across all modules in order to pick names that don't
17  *   conflict. Instead, the 'type' should be determined from introspecting what
18  *   kind of PHP variable (e.g., a type hinted interface) the controller
19  *   requires: https://www.drupal.org/node/2041907.
20  */
21 class EntityRouteAlterSubscriber implements EventSubscriberInterface {
22
23   /**
24    * The entity resolver manager.
25    *
26    * @var \Drupal\Core\Entity\EntityResolverManager
27    */
28   protected $resolverManager;
29
30   /**
31    * Constructs an EntityRouteAlterSubscriber instance.
32    *
33    * @param \Drupal\Core\Entity\EntityResolverManager $entity_resolver_manager
34    *   The entity resolver manager.
35    */
36   public function __construct(EntityResolverManager $entity_resolver_manager) {
37     $this->resolverManager = $entity_resolver_manager;
38   }
39
40   /**
41    * Applies parameter converters to route parameters.
42    *
43    * @param \Drupal\Core\Routing\RouteBuildEvent $event
44    *   The event to process.
45    */
46   public function onRoutingRouteAlterSetType(RouteBuildEvent $event) {
47     foreach ($event->getRouteCollection() as $route) {
48       $this->resolverManager->setRouteOptions($route);
49     }
50   }
51
52   /**
53    * {@inheritdoc}
54    */
55   public static function getSubscribedEvents() {
56     $events[RoutingEvents::ALTER][] = ['onRoutingRouteAlterSetType', -150];
57     return $events;
58   }
59
60 }