vendor/shopware/core/Content/Cms/Aggregate/CmsBlock/CmsBlockCollection.php line 11

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.  * @extends EntityCollection<CmsBlockEntity>
  7.  */
  8. class CmsBlockCollection extends EntityCollection
  9. {
  10.     public function getSlots(): CmsSlotCollection
  11.     {
  12.         $slots = new CmsSlotCollection();
  13.         foreach ($this->getIterator() as $block) {
  14.             if (!$block->getSlots()) {
  15.                 continue;
  16.             }
  17.             $slots->merge($block->getSlots());
  18.         }
  19.         return $slots;
  20.     }
  21.     public function filterBySectionPosition(string $position): CmsBlockCollection
  22.     {
  23.         return $this->filter(function (CmsBlockEntity $entity) use ($position) {
  24.             return $entity->getSectionPosition() === $position;
  25.         });
  26.     }
  27.     public function setSlots(CmsSlotCollection $slots): void
  28.     {
  29.         foreach ($this->getIterator() as $block) {
  30.             $blockSlots $block->getSlots();
  31.             if (!$blockSlots) {
  32.                 continue;
  33.             }
  34.             foreach ($blockSlots->getIds() as $slotId) {
  35.                 $blockSlots->set($slotId$slots->get($slotId));
  36.             }
  37.         }
  38.     }
  39.     public function getApiAlias(): string
  40.     {
  41.         return 'cms_page_block_collection';
  42.     }
  43.     protected function getExpectedClass(): string
  44.     {
  45.         return CmsBlockEntity::class;
  46.     }
  47. }