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

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