.../Drupal/Core/EventSubscriber/RouteAccessResponseSubscriber.php | 8 +++----- core/modules/rest/src/Plugin/rest/resource/EntityResource.php | 6 +++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/lib/Drupal/Core/EventSubscriber/RouteAccessResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RouteAccessResponseSubscriber.php index e0305b7..b2f1312 100644 --- a/core/lib/Drupal/Core/EventSubscriber/RouteAccessResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/RouteAccessResponseSubscriber.php @@ -48,11 +48,9 @@ public function onRespond(FilterResponseEvent $event) { * {@inheritdoc} */ public static function getSubscribedEvents() { - // Priority 110, so that it runs before FinishResponseSubscriber (0), which - // will expose the cacheability metadata in the form of headers, but also - // before DynamicPageCacheSubscriber (100), otherwise Dynamic Page Cache - // does not take the cacheability of route access into account. - $events[KernelEvents::RESPONSE][] = ['onRespond', 110]; + // Priority 10, so that it runs before FinishResponseSubscriber, which will + // expose the cacheability metadata in the form of headers. + $events[KernelEvents::RESPONSE][] = ['onRespond', 10]; return $events; } diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php index db6b0a1..23fa33b 100644 --- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php @@ -13,11 +13,13 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Field\FieldItemListInterface; +use Drupal\Core\Routing\AccessAwareRouterInterface; use Drupal\rest\Plugin\ResourceBase; use Drupal\rest\ResourceResponse; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\rest\ModifiedResourceResponse; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; @@ -119,8 +121,10 @@ public static function create(ContainerInterface $container, array $configuratio * * @throws \Symfony\Component\HttpKernel\Exception\HttpException */ - public function get(EntityInterface $entity) { + public function get(EntityInterface $entity, Request $request) { $response = new ResourceResponse($entity, 200); + // @todo Either remove the line below or remove this todo in https://www.drupal.org/project/drupal/issues/2973356 + $response->addCacheableDependency($request->attributes->get(AccessAwareRouterInterface::ACCESS_RESULT)); $response->addCacheableDependency($entity); if ($entity instanceof FieldableEntityInterface) {