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

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