vendor/shopware/platform/src/Core/Content/Cms/Aggregate/CmsBlock/CmsBlockCollection.php line 17

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Cms\Aggregate\CmsBlock;
  3. use Shopware\Core\Content\Cms\Aggregate\CmsSlot\CmsSlotCollection;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
  5. /**
  6.  * @method void                add(CmsBlockEntity $entity)
  7.  * @method void                set(string $key, CmsBlockEntity $entity)
  8.  * @method CmsBlockEntity[]    getIterator()
  9.  * @method CmsBlockEntity[]    getElements()
  10.  * @method CmsBlockEntity|null get(string $key)
  11.  * @method CmsBlockEntity|null first()
  12.  * @method CmsBlockEntity|null last()
  13.  */
  14. class CmsBlockCollection extends EntityCollection
  15. {
  16.     public function getSlots(): CmsSlotCollection
  17.     {
  18.         $slots = new CmsSlotCollection();
  19.         foreach ($this->getIterator() as $block) {
  20.             if (!$block->getSlots()) {
  21.                 continue;
  22.             }
  23.             $slots->merge($block->getSlots());
  24.         }
  25.         return $slots;
  26.     }
  27.     public function filterBySectionPosition(string $position): CmsBlockCollection
  28.     {
  29.         return $this->filter(function (CmsBlockEntity $entity) use ($position) {
  30.             return $entity->getSectionPosition() === $position;
  31.         });
  32.     }
  33.     public function setSlots(CmsSlotCollection $slots): void
  34.     {
  35.         foreach ($this->getIterator() as $block) {
  36.             $blockSlots $block->getSlots();
  37.             if (!$blockSlots) {
  38.                 continue;
  39.             }
  40.             foreach ($blockSlots->getIds() as $slotId) {
  41.                 $blockSlots->set($slotId$slots->get($slotId));
  42.             }
  43.         }
  44.     }
  45.     public function getApiAlias(): string
  46.     {
  47.         return 'cms_page_block_collection';
  48.     }
  49.     protected function getExpectedClass(): string
  50.     {
  51.         return CmsBlockEntity::class;
  52.     }
  53. }