getSlot example

$blocks = $section->getBlocks();
                if ($blocks === null) {
                    continue;
                }
                $blocks->sort(fn (CmsBlockEntity $a, CmsBlockEntity $b) => $a->getPosition() <=> $b->getPosition());

                foreach ($blocks as $block) {
                    $slots = $block->getSlots();
                    if ($slots === null) {
                        continue;
                    }
                    $slots->sort(fn (CmsSlotEntity $a, CmsSlotEntity $b) => $a->getSlot() <=> $b->getSlot());
                }
            }

            // step 3, find config overwrite             $overwrite = $config[$page->getId()] ?? $config;

            // step 4, overwrite slot config             $this->overwriteSlotConfig($page$overwrite);

            // step 5, resolve slot data             $this->loadSlotData($page$resolverContext);
        }
static::assertEquals(['overwrite' => true]$lastSlot->getConfig());
    }

    private function getBlock(): CmsBlockEntity
    {
        $block = new CmsBlockEntity();
        $block->setUniqueIdentifier(Uuid::randomHex());
        $block->setType('block');

        $block->setSlots(new CmsSlotCollection([
            $this->getSlot(),
            $this->getSlot(),
            $this->getSlot(),
            $this->getSlot(),
            $this->getSlot(),
        ]));

        return $block;
    }

    private function getSlot(): CmsSlotEntity
    {
        

    private ?array $slotCache = null;

    /** * @param string $key * @param CmsSlotEntity $entity */
    public function set($key$entity): void
    {
        parent::set($key$entity);

        $this->slotCache[$entity->getSlot()] = $entity;
    }

    /** * @param CmsSlotEntity $entity */
    public function add($entity): void
    {
        parent::add($entity);

        $this->slotCache[$entity->getSlot()] = $entity;
    }

    
use Shopware\Core\Content\Cms\Aggregate\CmsSlot\CmsSlotEntity;
use Shopware\Core\Framework\Uuid\Uuid;

/** * @internal */
class CmsSlotCollectionTest extends TestCase
{
    public function testGetSlot(): void
    {
        $collection = new CmsSlotCollection([
            $this->getSlot('left'),
            $this->getSlot('right'),
            $this->getSlot('top'),
            $this->getSlot('bottom'),
        ]);

        static::assertEquals('left', $collection->getSlot('left')->getSlot());
        static::assertEquals('right', $collection->getSlot('right')->getSlot());
        static::assertEquals('top', $collection->getSlot('top')->getSlot());
        static::assertEquals('bottom', $collection->getSlot('bottom')->getSlot());
    }

    

        $productId = Uuid::randomHex();
        $request = new Request([][]['productId' => $productId]);
        $salesChannelContext = $this->getSalesChannelContext();
        $reviews = $this->getCmsSlotConfig();

        $productPageLoader = $this->getProductPageLoaderWithProduct($productId$reviews$request$salesChannelContext);

        $page = $productPageLoader->load($request$salesChannelContext);

        /** @phpstan-ignore-next-line $slot */
        $slot = $page->getCmsPage()->getSections()->first()->getBlocks()->first()->getSlots()->first()->getSlot();

        static::assertEquals($reviewsjson_decode((string) $slot, true, 512, \JSON_THROW_ON_ERROR));
    }

    /** * @param array<string, array<string, array<string, array<string, array<string, string>>>>> $reviews */
    private function getProductPageLoaderWithProduct(string $productId, array $reviews, Request $request, SalesChannelContext $salesChannelContext): ProductPageLoader
    {
        $product = $this->getProductWithReviews($productId$reviews);

        
Home | Imprint | This part of the site doesn't use cookies.