vendor/shopware/core/Content/Cms/SalesChannel/CmsRoute.php line 47

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Cms\SalesChannel;
  3. use Shopware\Core\Content\Cms\Exception\PageNotFoundException;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
  6. use Shopware\Core\Framework\Log\Package;
  7. use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
  8. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. #[Route(defaults: ['_routeScope' => ['store-api']])]
  12. #[Package('content')]
  13. class CmsRoute extends AbstractCmsRoute
  14. {
  15.     /**
  16.      * @internal
  17.      */
  18.     public function __construct(private readonly SalesChannelCmsPageLoaderInterface $cmsPageLoader)
  19.     {
  20.     }
  21.     public function getDecorated(): AbstractCmsRoute
  22.     {
  23.         throw new DecorationPatternException(self::class);
  24.     }
  25.     #[Route(path'/store-api/cms/{id}'name'store-api.cms.detail'methods: ['GET''POST'])]
  26.     public function load(string $idRequest $requestSalesChannelContext $context): CmsRouteResponse
  27.     {
  28.         $criteria = new Criteria([$id]);
  29.         $slots $request->get('slots');
  30.         if (\is_string($slots)) {
  31.             $slots explode('|'$slots);
  32.         }
  33.         if (!empty($slots)) {
  34.             $criteria
  35.                 ->getAssociation('sections.blocks')
  36.                 ->addFilter(new EqualsAnyFilter('slots.id'$slots));
  37.         }
  38.         $pages $this->cmsPageLoader->load($request$criteria$context);
  39.         if (!$pages->has($id)) {
  40.             throw new PageNotFoundException($id);
  41.         }
  42.         return new CmsRouteResponse($pages->get($id));
  43.     }
  44. }