diff --git a/src/Api/Controller/GetWebResponseByPathController.php b/src/Api/Controller/GetWebResponseByPathController.php index d6ecf84b..2e924a4f 100644 --- a/src/Api/Controller/GetWebResponseByPathController.php +++ b/src/Api/Controller/GetWebResponseByPathController.php @@ -84,7 +84,10 @@ public function __invoke(?Request $request): ?WebResponseInterface $request->attributes->set('_locale', $resource->getTranslation()->getPreferredLocale()); } - return $this->webResponseDataTransformer->transform($resource, WebResponseInterface::class); + $data = $this->webResponseDataTransformer->transform($resource, WebResponseInterface::class); + $request->attributes->set('data', $data); + + return $data; } catch (ResourceNotFoundException | ResourceClassNotFoundException $exception) { throw $this->createNotFoundException($exception->getMessage(), $exception); } diff --git a/src/EventSubscriber/NodesSourcesAddHeadersSubscriber.php b/src/EventSubscriber/NodesSourcesAddHeadersSubscriber.php index 3cc95057..63808c9f 100644 --- a/src/EventSubscriber/NodesSourcesAddHeadersSubscriber.php +++ b/src/EventSubscriber/NodesSourcesAddHeadersSubscriber.php @@ -5,6 +5,7 @@ namespace RZ\Roadiz\CoreBundle\EventSubscriber; use ApiPlatform\Util\RequestAttributesExtractor; +use RZ\Roadiz\CoreBundle\Api\Model\WebResponseInterface; use RZ\Roadiz\CoreBundle\Entity\NodesSources; use RZ\Roadiz\CoreBundle\Preview\PreviewResolverInterface; use Symfony\Bundle\SecurityBundle\Security; @@ -55,6 +56,11 @@ public function onKernelResponse(ResponseEvent $event): void $resourceCacheHeaders = $attributes['cache_headers'] ?? []; $data = $request->attributes->get('data'); + // Work with WebResponse item instead of WebResponse itself + if ($data instanceof WebResponseInterface) { + $data = $data->getItem(); + } + // if the public-property is defined and not yet set; apply it to the response $public = $resourceCacheHeaders['public'] ?? null; if (null !== $public && !$response->headers->hasCacheControlDirective('public')) { diff --git a/src/EventSubscriber/NodesSourcesLinkHeaderEventSubscriber.php b/src/EventSubscriber/NodesSourcesLinkHeaderEventSubscriber.php index a0428d69..3c0b5c91 100644 --- a/src/EventSubscriber/NodesSourcesLinkHeaderEventSubscriber.php +++ b/src/EventSubscriber/NodesSourcesLinkHeaderEventSubscriber.php @@ -6,6 +6,7 @@ use Doctrine\Persistence\ManagerRegistry; use Psr\Link\EvolvableLinkProviderInterface; +use RZ\Roadiz\CoreBundle\Api\Model\WebResponseInterface; use RZ\Roadiz\CoreBundle\Entity\NodesSources; use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -38,6 +39,11 @@ public function onKernelView(ViewEvent $event): void $resources = $request->attributes->get('data'); $linkProvider = $request->attributes->get('_links', new GenericLinkProvider()); + // Work with WebResponse item instead of WebResponse itself + if ($resources instanceof WebResponseInterface) { + $resources = $resources->getItem(); + } + if (!$resources instanceof NodesSources || !$linkProvider instanceof EvolvableLinkProviderInterface) { return; }