X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Frest%2Fsrc%2FRouting%2FResourceRoutes.php;fp=web%2Fcore%2Fmodules%2Frest%2Fsrc%2FRouting%2FResourceRoutes.php;h=5ba4c5da62b28e6541dcc7c53ca53bdbba171009;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=c21f13cd961c4d74d48188db7d6c324fcbfe0000;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/rest/src/Routing/ResourceRoutes.php b/web/core/modules/rest/src/Routing/ResourceRoutes.php index c21f13cd9..5ba4c5da6 100644 --- a/web/core/modules/rest/src/Routing/ResourceRoutes.php +++ b/web/core/modules/rest/src/Routing/ResourceRoutes.php @@ -3,16 +3,18 @@ namespace Drupal\rest\Routing; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Routing\RouteSubscriberBase; +use Drupal\Core\Routing\RouteBuildEvent; +use Drupal\Core\Routing\RoutingEvents; use Drupal\rest\Plugin\Type\ResourcePluginManager; use Drupal\rest\RestResourceConfigInterface; use Psr\Log\LoggerInterface; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Routing\RouteCollection; /** * Subscriber for REST-style routes. */ -class ResourceRoutes extends RouteSubscriberBase { +class ResourceRoutes implements EventSubscriberInterface { /** * The plugin manager for REST plugins. @@ -54,18 +56,18 @@ class ResourceRoutes extends RouteSubscriberBase { /** * Alters existing routes for a specific collection. * - * @param \Symfony\Component\Routing\RouteCollection $collection - * The route collection for adding routes. + * @param \Drupal\Core\Routing\RouteBuildEvent $event + * The route build event. * @return array */ - protected function alterRoutes(RouteCollection $collection) { + public function onDynamicRouteEvent(RouteBuildEvent $event) { // Iterate over all enabled REST resource config entities. /** @var \Drupal\rest\RestResourceConfigInterface[] $resource_configs */ $resource_configs = $this->resourceConfigStorage->loadMultiple(); foreach ($resource_configs as $resource_config) { if ($resource_config->status()) { $resource_routes = $this->getRoutesForResourceConfig($resource_config); - $collection->addCollection($resource_routes); + $event->getRouteCollection()->addCollection($resource_routes); } } } @@ -131,4 +133,12 @@ class ResourceRoutes extends RouteSubscriberBase { return $collection; } + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() { + $events[RoutingEvents::DYNAMIC] = 'onDynamicRouteEvent'; + return $events; + } + }