diff --git a/core/modules/rest/src/RequestHandler.php b/core/modules/rest/src/RequestHandler.php index 63c9924..83a4311 100644 --- a/core/modules/rest/src/RequestHandler.php +++ b/core/modules/rest/src/RequestHandler.php @@ -26,13 +26,6 @@ class RequestHandler implements ContainerInjectionInterface { /** - * The resource configuration storage. - * - * @var \Drupal\Core\Entity\EntityStorageInterface - */ - protected $resourceStorage; - - /** * The config factory. * * @var \Drupal\Core\Config\ConfigFactoryInterface @@ -49,15 +42,12 @@ class RequestHandler implements ContainerInjectionInterface { /** * Creates a new RequestHandler instance. * - * @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage - * The resource configuration storage. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. * @param \Symfony\Component\Serializer\SerializerInterface|\Symfony\Component\Serializer\Encoder\DecoderInterface $serializer * The serializer. */ - public function __construct(EntityStorageInterface $entity_storage, ConfigFactoryInterface $config_factory, SerializerInterface $serializer) { - $this->resourceStorage = $entity_storage; + public function __construct(ConfigFactoryInterface $config_factory, SerializerInterface $serializer) { $this->configFactory = $config_factory; $this->serializer = $serializer; } @@ -67,7 +57,6 @@ public function __construct(EntityStorageInterface $entity_storage, ConfigFactor */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity_type.manager')->getStorage('rest_resource_config'), $container->get('config.factory'), $container->get('serializer') ); @@ -80,20 +69,17 @@ public static function create(ContainerInterface $container) { * The route match. * @param \Symfony\Component\HttpFoundation\Request $request * The HTTP request object. - * @param string $_rest_resource_config + * @param \Drupal\rest\RestResourceConfigInterface $_rest_resource_config * Rest resource csonfig ID. * - * @return \Symfony\Component\HttpFoundation\Response|\Drupal\rest\ResourceResponseInterface + * @return \Drupal\rest\ResourceResponseInterface|\Symfony\Component\HttpFoundation\Response * The REST resource response. */ - public function handle(RouteMatchInterface $route_match, Request $request, $_rest_resource_config) { - /** @var \Drupal\rest\RestResourceConfigInterface $resource_config */ - $resource_config = $this->resourceStorage->load($_rest_resource_config); - - $response = $this->delegateToRestResourcePlugin($route_match, $request, $resource_config->getResourcePlugin()); + public function handle(RouteMatchInterface $route_match, Request $request, RestResourceConfigInterface $_rest_resource_config) { + $response = $this->delegateToRestResourcePlugin($route_match, $request, $_rest_resource_config->getResourcePlugin()); if ($response instanceof CacheableResponseInterface) { - $response->addCacheableDependency($resource_config); + $response->addCacheableDependency($_rest_resource_config); // Add global rest settings config's cache tag, for BC flags. // @see \Drupal\rest\Plugin\rest\resource\EntityResource::permissions() // @see \Drupal\rest\EventSubscriber\RestConfigSubscriber diff --git a/core/modules/rest/src/Routing/ResourceRoutes.php b/core/modules/rest/src/Routing/ResourceRoutes.php index 5ba4c5d..7bae458 100644 --- a/core/modules/rest/src/Routing/ResourceRoutes.php +++ b/core/modules/rest/src/Routing/ResourceRoutes.php @@ -126,6 +126,11 @@ protected function getRoutesForResourceConfig(RestResourceConfigInterface $rest_ } $route->setOption('_auth', $rest_resource_config->getAuthenticationProviders($method)); $route->setDefault('_rest_resource_config', $rest_resource_config->id()); + $route->setOption('parameters', $route->getOption('parameters') + [ + '_rest_resource_config' => [ + 'type' => $rest_resource_config->getEntityTypeId(), + ], + ]); $collection->add("rest.$name", $route); }