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

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