vendor/shopware/core/Content/Cms/SalesChannel/SalesChannelCmsPageRepository.php line 29

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Cms\SalesChannel;
  3. use Shopware\Core\Content\Cms\Aggregate\CmsBlock\CmsBlockEntity;
  4. use Shopware\Core\Content\Cms\Aggregate\CmsSection\CmsSectionEntity;
  5. use Shopware\Core\Content\Cms\CmsPageCollection;
  6. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  9. use Shopware\Core\Framework\Feature;
  10. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  11. /**
  12.  * @deprecated tag:v6.5.0 - SalesChannelCmsPageRepository will be removed.
  13.  */
  14. class SalesChannelCmsPageRepository
  15. {
  16.     private EntityRepositoryInterface $cmsPageRepository;
  17.     /**
  18.      * @internal
  19.      */
  20.     public function __construct(EntityRepositoryInterface $repository)
  21.     {
  22.         $this->cmsPageRepository $repository;
  23.     }
  24.     public function read(array $idsSalesChannelContext $context): CmsPageCollection
  25.     {
  26.         Feature::triggerDeprecationOrThrow(
  27.             'v6.5.0.0',
  28.             Feature::deprecatedClassMessage(__CLASS__'v6.5.0.0')
  29.         );
  30.         $criteria = new Criteria($ids);
  31.         return $this->readCmsPages($criteria$context);
  32.     }
  33.     public function getPagesByType(string $typeSalesChannelContext $context): CmsPageCollection
  34.     {
  35.         Feature::triggerDeprecationOrThrow(
  36.             'v6.5.0.0',
  37.             Feature::deprecatedClassMessage(__CLASS__'v6.5.0.0')
  38.         );
  39.         $criteria = new Criteria();
  40.         $criteria->addFilter(new EqualsFilter('cms_page.type'$type));
  41.         return $this->readCmsPages($criteria$context);
  42.     }
  43.     private function readCmsPages(Criteria $criteriaSalesChannelContext $context): CmsPageCollection
  44.     {
  45.         Feature::triggerDeprecationOrThrow(
  46.             'v6.5.0.0',
  47.             Feature::deprecatedClassMessage(__CLASS__'v6.5.0.0')
  48.         );
  49.         $criteria->addAssociation('sections.backgroundMedia')
  50.             ->addAssociation('sections.blocks.backgroundMedia')
  51.             ->addAssociation('sections.blocks.slots');
  52.         /** @var CmsPageCollection $pages */
  53.         $pages $this->cmsPageRepository->search($criteria$context->getContext())->getEntities();
  54.         foreach ($pages as $page) {
  55.             if ($page->getSections() === null) {
  56.                 continue;
  57.             }
  58.             $page->getSections()->sort(function (CmsSectionEntity $aCmsSectionEntity $b) {
  59.                 return $a->getPosition() <=> $b->getPosition();
  60.             });
  61.             foreach ($page->getSections() as $section) {
  62.                 if ($section->getBlocks() === null) {
  63.                     continue;
  64.                 }
  65.                 $section->getBlocks()->sort(function (CmsBlockEntity $aCmsBlockEntity $b) {
  66.                     return $a->getPosition() <=> $b->getPosition();
  67.                 });
  68.             }
  69.         }
  70.         return $pages;
  71.     }
  72. }