lib/Core/Mapper/BlockMapper.php
public function mapBlock(PersistenceBlock $block, ?array $locales = null, bool $useMainLocale = true): Block
    {
        try {
            $blockDefinition = $this->blockDefinitionRegistry->getBlockDefinition(
                $block->definitionIdentifier
            );
        } catch (BlockDefinitionException $e) {
            $blockDefinition = new NullBlockDefinition($block->definitionIdentifier);
        }

        $locales = is_array($locales) && count($locales) > 0 ? $locales : [$block->mainLocale];
        if ($useMainLocale && $block->alwaysAvailable) {
            $locales[] = $block->mainLocale;
        }

        $validLocales = array_unique(array_intersect($locales, $block->availableLocales));
        if (count($validLocales) === 0) {
            throw new NotFoundException('block', $block->id);
        }

        /** @var string $blockLocale */
        $blockLocale = array_values($validLocales)[0];
        $untranslatableParams = iterator_to_array(
            $this->parameterMapper->extractUntranslatableParameters(
                $blockDefinition,
                $block->parameters[$block->mainLocale]
            )
        );

        $blockData = [
            'id' => $block->id,
            'layoutId' => $block->layoutId,
            'definition' => $blockDefinition,
            'viewType' => $block->viewType,
            'itemViewType' => $block->itemViewType,
            'name' => $block->name,
            'position' => $block->position,
            'parentBlockId' => $block->depth > 1 ? $block->parentId : null,
            'parentPlaceholder' => $block->depth > 1 ? $block->placeholder : null,
            'status' => $block->status,
            'placeholders' => iterator_to_array($this->mapPlaceholders($block, $blockDefinition, $locales)),
            'collections' => new LazyCollection(
                function () use ($block, $locales): array {
                    return array_map(
                        function (PersistenceCollection $collection) use ($locales): Collection {
                            return $this->collectionMapper->mapCollection($collection, $locales);
                        },
                        iterator_to_array($this->loadCollections($block))
                    );
                }
            ),
            'configs' => iterator_to_array(
                $this->configMapper->mapConfig(
                    $block->config,
                    $blockDefinition->getConfigDefinitions()
                )
            ),
            'isTranslatable' => $block->isTranslatable,
            'mainLocale' => $block->mainLocale,
            'alwaysAvailable' => $block->alwaysAvailable,
            'availableLocales' => $block->availableLocales,
            'locale' => $blockLocale,
            'parameters' => iterator_to_array(
                $this->parameterMapper->mapParameters(
                    $blockDefinition,
                    $untranslatableParams + $block->parameters[$blockLocale]
                )
            ),
        ];

        return Block::fromArray($blockData);
    }
public function mapBlock(PersistenceBlock $block, ?array $locales = null, bool $useMainLocale = true): Block
    {
        try {
            $blockDefinition = $this->blockDefinitionRegistry->getBlockDefinition(
                $block->definitionIdentifier
            );
        } catch (BlockDefinitionException $e) {
            $blockDefinition = new NullBlockDefinition($block->definitionIdentifier);
        }

        $locales = is_array($locales) && count($locales) > 0 ? $locales : [$block->mainLocale];
        if ($useMainLocale && $block->alwaysAvailable) {
            $locales[] = $block->mainLocale;
        }

        $validLocales = array_unique(array_intersect($locales, $block->availableLocales));
        if (count($validLocales) === 0) {
            throw new NotFoundException('block', $block->id);
        }

        /** @var string $blockLocale */
        $blockLocale = array_values($validLocales)[0];
        $untranslatableParams = iterator_to_array(
            $this->parameterMapper->extractUntranslatableParameters(
                $blockDefinition,
                $block->parameters[$block->mainLocale]
            )
        );

        $blockData = [
            'id' => $block->id,
            'layoutId' => $block->layoutId,
            'definition' => $blockDefinition,
            'viewType' => $block->viewType,
            'itemViewType' => $block->itemViewType,
            'name' => $block->name,
            'position' => $block->position,
            'parentBlockId' => $block->depth > 1 ? $block->parentId : null,
            'parentPlaceholder' => $block->depth > 1 ? $block->placeholder : null,
            'status' => $block->status,
            'placeholders' => iterator_to_array($this->mapPlaceholders($block, $blockDefinition, $locales)),
            'collections' => new LazyCollection(
                function () use ($block, $locales): array {
                    return array_map(
                        function (PersistenceCollection $collection) use ($locales): Collection {
                            return $this->collectionMapper->mapCollection($collection, $locales);
                        },
                        iterator_to_array($this->loadCollections($block))
                    );
                }
            ),
            'configs' => iterator_to_array(
                $this->configMapper->mapConfig(
                    $block->config,
                    $blockDefinition->getConfigDefinitions()
                )
            ),
            'isTranslatable' => $block->isTranslatable,
            'mainLocale' => $block->mainLocale,
            'alwaysAvailable' => $block->alwaysAvailable,
            'availableLocales' => $block->availableLocales,
            'locale' => $blockLocale,
            'parameters' => iterator_to_array(
                $this->parameterMapper->mapParameters(
                    $blockDefinition,
                    $untranslatableParams + $block->parameters[$blockLocale]
                )
            ),
        ];

        return Block::fromArray($blockData);
    }
public function mapBlock ( PersistenceBlock $ block , ? array $ locales = null , bool $ useMainLocale = true ) : Block { try { $ blockDefinition = $ this -> blockDefinitionRegistry -> getBlockDefinition ( $ block -> definitionIdentifier ) ; } catch ( BlockDefinitionException $ e ) { $ blockDefinition = new NullBlockDefinition ( $ block -> definitionIdentifier ) ; } $ locales = is_array ( $ locales ) && count ( $ locales ) > 0 ? $ locales : [ $ block -> mainLocale ] ; if ( $ useMainLocale && $ block -> alwaysAvailable ) { $ locales [ ] = $ block -> mainLocale ; } $ validLocales = array_unique ( array_intersect ( $ locales , $ block -> availableLocales ) ) ; if ( count ( $ validLocales ) === 0 ) { throw new NotFoundException ( 'block' , $ block -> id ) ; } /** @var string $blockLocale */ $ blockLocale = array_values ( $ validLocales ) [ 0 ] ; $ untranslatableParams = iterator_to_array ( $ this -> parameterMapper -> extractUntranslatableParameters ( $ blockDefinition , $ block -> parameters [ $ block -> mainLocale ] ) ) ; $ blockData = [ 'id' => $ block -> id , 'layoutId' => $ block -> layoutId , 'definition' => $ blockDefinition , 'viewType' => $ block -> viewType , 'itemViewType' => $ block -> itemViewType , 'name' => $ block -> name , 'position' => $ block -> position , 'parentBlockId' => $ block -> depth > 1 ? $ block -> parentId : null , 'parentPlaceholder' => $ block -> depth > 1 ? $ block -> placeholder : null , 'status' => $ block -> status , 'placeholders' => iterator_to_array ( $ this -> mapPlaceholders ( $ block , $ blockDefinition , $ locales ) ) , 'collections' => new LazyCollection ( function ( ) use ( $ block , $ locales ) : array { return array_map ( function ( PersistenceCollection $ collection ) use ( $ locales ) : Collection { return $ this -> collectionMapper -> mapCollection ( $ collection , $ locales ) ; } , iterator_to_array ( $ this -> loadCollections ( $ block ) ) ) ; } ) , 'configs' => iterator_to_array ( $ this -> configMapper -> mapConfig ( $ block -> config , $ blockDefinition -> getConfigDefinitions ( ) ) ) , 'isTranslatable' => $ block -> isTranslatable , 'mainLocale' => $ block -> mainLocale , 'alwaysAvailable' => $ block -> alwaysAvailable , 'availableLocales' => $ block -> availableLocales , 'locale' => $ blockLocale , 'parameters' => iterator_to_array ( $ this -> parameterMapper -> mapParameters ( $ blockDefinition , $ untranslatableParams + $ block -> parameters [ $ blockLocale ] ) ) , ] ; return Block :: fromArray ( $ blockData ) ; }
Builds the API block value from persistence one.

If not empty, the first available locale in $locales array will be returned.

If the block is always available and $useMainLocale is set to true,
block in main locale will be returned if none of the locales in $locales
array are found.

@throws \Netgen\BlockManager\Exception\NotFoundException If the block does not have any requested translations
Builds the API block value from persistence one .