lib/Core/Service/BlockService.php
private function internalCreateBlock(
        APIBlockCreateStruct $blockCreateStruct,
        PersistenceBlock $targetBlock,
        string $placeholder,
        ?int $position = null
    ): Block {
        $persistenceLayout = $this->layoutHandler->loadLayout($targetBlock->layoutId, Value::STATUS_DRAFT);

        $createdBlock = $this->transaction(
            function () use ($blockCreateStruct, $persistenceLayout, $targetBlock, $placeholder, $position): PersistenceBlock {
                $blockDefinition = $blockCreateStruct->getDefinition();

                $createdBlock = $this->blockHandler->createBlock(
                    BlockCreateStruct::fromArray(
                        [
                            'status' => $targetBlock->status,
                            'position' => $position,
                            'definitionIdentifier' => $blockDefinition->getIdentifier(),
                            'viewType' => $blockCreateStruct->viewType,
                            'itemViewType' => $blockCreateStruct->itemViewType,
                            'name' => $blockCreateStruct->name,
                            'alwaysAvailable' => $blockCreateStruct->alwaysAvailable,
                            'isTranslatable' => $blockCreateStruct->isTranslatable,
                            'parameters' => iterator_to_array(
                                $this->parameterMapper->serializeValues(
                                    $blockDefinition,
                                    $blockCreateStruct->getParameterValues()
                                )
                            ),
                            'config' => iterator_to_array(
                                $this->configMapper->serializeValues(
                                    $blockCreateStruct->getConfigStructs(),
                                    $blockDefinition->getConfigDefinitions()
                                )
                            ),
                        ]
                    ),
                    $persistenceLayout,
                    $targetBlock,
                    $placeholder
                );

                $collectionCreateStructs = $blockCreateStruct->getCollectionCreateStructs();
                if (count($collectionCreateStructs) > 0) {
                    foreach ($collectionCreateStructs as $identifier => $collectionCreateStruct) {
                        $createdCollection = $this->collectionHandler->createCollection(
                            CollectionCreateStruct::fromArray(
                                [
                                    'status' => Value::STATUS_DRAFT,
                                    'offset' => $collectionCreateStruct->offset,
                                    'limit' => $collectionCreateStruct->limit,
                                    'alwaysAvailable' => $blockCreateStruct->alwaysAvailable,
                                    'isTranslatable' => $blockCreateStruct->isTranslatable,
                                    'mainLocale' => $persistenceLayout->mainLocale,
                                ]
                            )
                        );

                        if ($collectionCreateStruct->queryCreateStruct instanceof APIQueryCreateStruct) {
                            $queryType = $collectionCreateStruct->queryCreateStruct->getQueryType();
                            $this->collectionHandler->createQuery(
                                $createdCollection,
                                QueryCreateStruct::fromArray(
                                    [
                                        'type' => $queryType->getType(),
                                        'parameters' => iterator_to_array(
                                            $this->parameterMapper->serializeValues(
                                                $queryType,
                                                $collectionCreateStruct->queryCreateStruct->getParameterValues()
                                            )
                                        ),
                                    ]
                                )
                            );
                        }

                        if ($blockCreateStruct->isTranslatable) {
                            foreach ($persistenceLayout->availableLocales as $locale) {
                                if ($locale !== $persistenceLayout->mainLocale) {
                                    $createdCollection = $this->collectionHandler->createCollectionTranslation(
                                        $createdCollection,
                                        $locale,
                                        $createdCollection->mainLocale
                                    );
                                }
                            }
                        }

                        $this->blockHandler->createCollectionReference(
                            $createdBlock,
                            $createdCollection,
                            (string) $identifier
                        );
                    }
                }

                return $createdBlock;
            }
        );

        return $this->mapper->mapBlock($createdBlock);
    }
private function internalCreateBlock(
        APIBlockCreateStruct $blockCreateStruct,
        PersistenceBlock $targetBlock,
        string $placeholder,
        ?int $position = null
    ): Block {
        $persistenceLayout = $this->layoutHandler->loadLayout($targetBlock->layoutId, Value::STATUS_DRAFT);

        $createdBlock = $this->transaction(
            function () use ($blockCreateStruct, $persistenceLayout, $targetBlock, $placeholder, $position): PersistenceBlock {
                $blockDefinition = $blockCreateStruct->getDefinition();

                $createdBlock = $this->blockHandler->createBlock(
                    BlockCreateStruct::fromArray(
                        [
                            'status' => $targetBlock->status,
                            'position' => $position,
                            'definitionIdentifier' => $blockDefinition->getIdentifier(),
                            'viewType' => $blockCreateStruct->viewType,
                            'itemViewType' => $blockCreateStruct->itemViewType,
                            'name' => $blockCreateStruct->name,
                            'alwaysAvailable' => $blockCreateStruct->alwaysAvailable,
                            'isTranslatable' => $blockCreateStruct->isTranslatable,
                            'parameters' => iterator_to_array(
                                $this->parameterMapper->serializeValues(
                                    $blockDefinition,
                                    $blockCreateStruct->getParameterValues()
                                )
                            ),
                            'config' => iterator_to_array(
                                $this->configMapper->serializeValues(
                                    $blockCreateStruct->getConfigStructs(),
                                    $blockDefinition->getConfigDefinitions()
                                )
                            ),
                        ]
                    ),
                    $persistenceLayout,
                    $targetBlock,
                    $placeholder
                );

                $collectionCreateStructs = $blockCreateStruct->getCollectionCreateStructs();
                if (count($collectionCreateStructs) > 0) {
                    foreach ($collectionCreateStructs as $identifier => $collectionCreateStruct) {
                        $createdCollection = $this->collectionHandler->createCollection(
                            CollectionCreateStruct::fromArray(
                                [
                                    'status' => Value::STATUS_DRAFT,
                                    'offset' => $collectionCreateStruct->offset,
                                    'limit' => $collectionCreateStruct->limit,
                                    'alwaysAvailable' => $blockCreateStruct->alwaysAvailable,
                                    'isTranslatable' => $blockCreateStruct->isTranslatable,
                                    'mainLocale' => $persistenceLayout->mainLocale,
                                ]
                            )
                        );

                        if ($collectionCreateStruct->queryCreateStruct instanceof APIQueryCreateStruct) {
                            $queryType = $collectionCreateStruct->queryCreateStruct->getQueryType();
                            $this->collectionHandler->createQuery(
                                $createdCollection,
                                QueryCreateStruct::fromArray(
                                    [
                                        'type' => $queryType->getType(),
                                        'parameters' => iterator_to_array(
                                            $this->parameterMapper->serializeValues(
                                                $queryType,
                                                $collectionCreateStruct->queryCreateStruct->getParameterValues()
                                            )
                                        ),
                                    ]
                                )
                            );
                        }

                        if ($blockCreateStruct->isTranslatable) {
                            foreach ($persistenceLayout->availableLocales as $locale) {
                                if ($locale !== $persistenceLayout->mainLocale) {
                                    $createdCollection = $this->collectionHandler->createCollectionTranslation(
                                        $createdCollection,
                                        $locale,
                                        $createdCollection->mainLocale
                                    );
                                }
                            }
                        }

                        $this->blockHandler->createCollectionReference(
                            $createdBlock,
                            $createdCollection,
                            (string) $identifier
                        );
                    }
                }

                return $createdBlock;
            }
        );

        return $this->mapper->mapBlock($createdBlock);
    }
private function internalCreateBlock ( APIBlockCreateStruct $ blockCreateStruct , PersistenceBlock $ targetBlock , string $ placeholder , ? int $ position = null ) : Block { $ persistenceLayout = $ this -> layoutHandler -> loadLayout ( $ targetBlock -> layoutId , Value :: STATUS_DRAFT ) ; $ createdBlock = $ this -> transaction ( function ( ) use ( $ blockCreateStruct , $ persistenceLayout , $ targetBlock , $ placeholder , $ position ) : PersistenceBlock { $ blockDefinition = $ blockCreateStruct -> getDefinition ( ) ; $ createdBlock = $ this -> blockHandler -> createBlock ( BlockCreateStruct :: fromArray ( [ 'status' => $ targetBlock -> status , 'position' => $ position , 'definitionIdentifier' => $ blockDefinition -> getIdentifier ( ) , 'viewType' => $ blockCreateStruct -> viewType , 'itemViewType' => $ blockCreateStruct -> itemViewType , 'name' => $ blockCreateStruct -> name , 'alwaysAvailable' => $ blockCreateStruct -> alwaysAvailable , 'isTranslatable' => $ blockCreateStruct -> isTranslatable , 'parameters' => iterator_to_array ( $ this -> parameterMapper -> serializeValues ( $ blockDefinition , $ blockCreateStruct -> getParameterValues ( ) ) ) , 'config' => iterator_to_array ( $ this -> configMapper -> serializeValues ( $ blockCreateStruct -> getConfigStructs ( ) , $ blockDefinition -> getConfigDefinitions ( ) ) ) , ] ) , $ persistenceLayout , $ targetBlock , $ placeholder ) ; $ collectionCreateStructs = $ blockCreateStruct -> getCollectionCreateStructs ( ) ; if ( count ( $ collectionCreateStructs ) > 0 ) { foreach ( $ collectionCreateStructs as $ identifier => $ collectionCreateStruct ) { $ createdCollection = $ this -> collectionHandler -> createCollection ( CollectionCreateStruct :: fromArray ( [ 'status' => Value :: STATUS_DRAFT , 'offset' => $ collectionCreateStruct -> offset , 'limit' => $ collectionCreateStruct -> limit , 'alwaysAvailable' => $ blockCreateStruct -> alwaysAvailable , 'isTranslatable' => $ blockCreateStruct -> isTranslatable , 'mainLocale' => $ persistenceLayout -> mainLocale , ] ) ) ; if ( $ collectionCreateStruct -> queryCreateStruct instanceof APIQueryCreateStruct ) { $ queryType = $ collectionCreateStruct -> queryCreateStruct -> getQueryType ( ) ; $ this -> collectionHandler -> createQuery ( $ createdCollection , QueryCreateStruct :: fromArray ( [ 'type' => $ queryType -> getType ( ) , 'parameters' => iterator_to_array ( $ this -> parameterMapper -> serializeValues ( $ queryType , $ collectionCreateStruct -> queryCreateStruct -> getParameterValues ( ) ) ) , ] ) ) ; } if ( $ blockCreateStruct -> isTranslatable ) { foreach ( $ persistenceLayout -> availableLocales as $ locale ) { if ( $ locale !== $ persistenceLayout -> mainLocale ) { $ createdCollection = $ this -> collectionHandler -> createCollectionTranslation ( $ createdCollection , $ locale , $ createdCollection -> mainLocale ) ; } } } $ this -> blockHandler -> createCollectionReference ( $ createdBlock , $ createdCollection , ( string ) $ identifier ) ; } } return $ createdBlock ; } ) ; return $ this -> mapper -> mapBlock ( $ createdBlock ) ; }
Creates a block at specified target block and placeholder and position.

If position is not provided, block is placed at the end of the placeholder.

This is an internal method unifying creating a block in a zone and a parent block.
Creates a block at specified target block and placeholder and position .