setSlots example

private function loadSlotData(CmsPageEntity $page, ResolverContext $resolverContext): void
    {
        $sections = $page->getSections();
        if ($sections === null) {
            return;
        }

        $blocks = $sections->getBlocks();
        $slots = $this->slotDataResolver->resolve($blocks->getSlots()$resolverContext);

        $blocks->setSlots($slots);
    }

    /** * @param array<string, mixed> $config */
    private function overwriteSlotConfig(CmsPageEntity $page, array $config): void
    {
        $sections = $page->getSections();
        if ($sections === null) {
            return;
        }

        
$cmsSectionEntity = new CmsSectionEntity();
        $cmsSectionEntity->setId(Uuid::randomHex());

        $cmsBlockEntity = new CmsBlockEntity();
        $cmsBlockEntity->setId(Uuid::randomHex());

        $cmsSlotEntity = new CmsSlotEntity();
        $cmsSlotEntity->setId(Uuid::randomHex());
        $cmsSlotEntity->setSlot(json_encode($productEntity->getTranslated(), \JSON_THROW_ON_ERROR));

        $cmsBlockEntity->setSlots(new CmsSlotCollection([$cmsSlotEntity]));
        $cmsSectionEntity->setBlocks(new CmsBlockCollection([$cmsBlockEntity]));
        $cmsPageEntity->setSections(new CmsSectionCollection([$cmsSectionEntity]));

        return $cmsPageEntity;
    }
}
$cmsSectionEntity = new CmsSectionEntity();
        $cmsSectionEntity->setId(Uuid::randomHex());

        $cmsBlockEntity = new CmsBlockEntity();
        $cmsBlockEntity->setId(Uuid::randomHex());

        $cmsSlotEntity = new CmsSlotEntity();
        $cmsSlotEntity->setId(Uuid::randomHex());
        $cmsSlotEntity->setSlot(json_encode($productEntity->getTranslated(), \JSON_THROW_ON_ERROR));

        $cmsBlockEntity->setSlots(new CmsSlotCollection([$cmsSlotEntity]));
        $cmsSectionEntity->setBlocks(new CmsBlockCollection([$cmsBlockEntity]));
        $cmsPageEntity->setSections(new CmsSectionCollection([$cmsSectionEntity]));

        return $cmsPageEntity;
    }

    /** * @return array<string, array<string, array<string, array<string, array<string, string>>>>> */
    private function getCmsSlotConfig(): array
    {
        
$fieldConfig->add(new FieldConfig('product', FieldConfig::SOURCE_STATIC, $product->getId()));

        $slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('id');
        $slot->setSlot('product-box');
        $slot->setType('product-box');
        $slot->setFieldConfig($fieldConfig);
        $slot->getFieldConfig();

        $cmsBlock = new CmsBlockEntity();
        $cmsBlock->setUniqueIdentifier('block1');
        $cmsBlock->setSlots(new CmsSlotCollection([$slot]));

        $cmsSection = new CmsSectionEntity();
        $cmsSection->setUniqueIdentifier('section1');
        $cmsSection->setBlocks(new CmsBlockCollection([$cmsBlock]));

        $cmsPage = new CmsPageEntity();
        $cmsPage->setSections(new CmsSectionCollection([$cmsSection]));

        $product->setCmsPage($cmsPage);

        return $slot;
    }
$collection = new CmsBlockCollection();
        $collection->add($this->getBlock());
        $collection->add($this->getBlock());
        $collection->add($this->getBlock());

        $slots = $collection->getSlots();

        /** @var CmsSlotEntity $slot */
        $slot = $slots->last();
        $slot->setConfig(['overwrite' => true]);

        $collection->setSlots($slots);

        /** @var CmsSlotEntity $lastSlot */
        $lastSlot = $collection->getSlots()->last();

        static::assertEquals(['overwrite' => true]$lastSlot->getConfig());
    }

    private function getBlock(): CmsBlockEntity
    {
        $block = new CmsBlockEntity();
        $block->setUniqueIdentifier(Uuid::randomHex());
        
Home | Imprint | This part of the site doesn't use cookies.