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

Open in your IDE?
  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\Framework\Routing\Annotation\RouteScope;
  9. use Shopware\Core\Framework\Routing\Annotation\Since;
  10. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. /**
  14.  * @Route(defaults={"_routeScope"={"store-api"}})
  15.  */
  16. #[Package('content')]
  17. class CmsRoute extends AbstractCmsRoute
  18. {
  19.     /**
  20.      * @var SalesChannelCmsPageLoaderInterface
  21.      */
  22.     private $cmsPageLoader;
  23.     /**
  24.      * @internal
  25.      */
  26.     public function __construct(SalesChannelCmsPageLoaderInterface $cmsPageLoader)
  27.     {
  28.         $this->cmsPageLoader $cmsPageLoader;
  29.     }
  30.     public function getDecorated(): AbstractCmsRoute
  31.     {
  32.         throw new DecorationPatternException(self::class);
  33.     }
  34.     /**
  35.      * @Since("6.2.0.0")
  36.      * @Route("/store-api/cms/{id}", name="store-api.cms.detail", methods={"GET", "POST"})
  37.      */
  38.     public function load(string $idRequest $requestSalesChannelContext $context): CmsRouteResponse
  39.     {
  40.         $criteria = new Criteria([$id]);
  41.         $slots $request->get('slots');
  42.         if (\is_string($slots)) {
  43.             $slots explode('|'$slots);
  44.         }
  45.         if (!empty($slots)) {
  46.             $criteria
  47.                 ->getAssociation('sections.blocks')
  48.                 ->addFilter(new EqualsAnyFilter('slots.id'$slots));
  49.         }
  50.         $pages $this->cmsPageLoader->load($request$criteria$context);
  51.         if (!$pages->has($id)) {
  52.             throw new PageNotFoundException($id);
  53.         }
  54.         return new CmsRouteResponse($pages->get($id));
  55.     }
  56. }