lib/Core/Mapper/CollectionMapper.php
public function mapCollection(PersistenceCollection $collection, ?array $locales = null, bool $useMainLocale = true): Collection
    {
        $locales = is_array($locales) && count($locales) > 0 ? $locales : [$collection->mainLocale];
        if ($useMainLocale && $collection->alwaysAvailable) {
            $locales[] = $collection->mainLocale;
        }

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

        $collectionData = [
            'id' => $collection->id,
            'status' => $collection->status,
            'offset' => $collection->offset,
            'limit' => $collection->limit,
            'items' => new LazyCollection(
                function () use ($collection): array {
                    return array_map(
                        function (PersistenceItem $item): Item {
                            return $this->mapItem($item);
                        },
                        $this->collectionHandler->loadCollectionItems($collection)
                    );
                }
            ),
            'query' => function () use ($collection, $locales): ?Query {
                try {
                    $persistenceQuery = $this->collectionHandler->loadCollectionQuery($collection);
                } catch (NotFoundException $e) {
                    return null;
                }

                return $this->mapQuery($persistenceQuery, $locales, false);
            },
            'isTranslatable' => $collection->isTranslatable,
            'mainLocale' => $collection->mainLocale,
            'alwaysAvailable' => $collection->alwaysAvailable,
            'availableLocales' => $collection->availableLocales,
            'locale' => array_values($validLocales)[0],
        ];

        return Collection::fromArray($collectionData);
    }
public function mapCollection(PersistenceCollection $collection, ?array $locales = null, bool $useMainLocale = true): Collection
    {
        $locales = is_array($locales) && count($locales) > 0 ? $locales : [$collection->mainLocale];
        if ($useMainLocale && $collection->alwaysAvailable) {
            $locales[] = $collection->mainLocale;
        }

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

        $collectionData = [
            'id' => $collection->id,
            'status' => $collection->status,
            'offset' => $collection->offset,
            'limit' => $collection->limit,
            'items' => new LazyCollection(
                function () use ($collection): array {
                    return array_map(
                        function (PersistenceItem $item): Item {
                            return $this->mapItem($item);
                        },
                        $this->collectionHandler->loadCollectionItems($collection)
                    );
                }
            ),
            'query' => function () use ($collection, $locales): ?Query {
                try {
                    $persistenceQuery = $this->collectionHandler->loadCollectionQuery($collection);
                } catch (NotFoundException $e) {
                    return null;
                }

                return $this->mapQuery($persistenceQuery, $locales, false);
            },
            'isTranslatable' => $collection->isTranslatable,
            'mainLocale' => $collection->mainLocale,
            'alwaysAvailable' => $collection->alwaysAvailable,
            'availableLocales' => $collection->availableLocales,
            'locale' => array_values($validLocales)[0],
        ];

        return Collection::fromArray($collectionData);
    }
public function mapCollection ( PersistenceCollection $ collection , ? array $ locales = null , bool $ useMainLocale = true ) : Collection { $ locales = is_array ( $ locales ) && count ( $ locales ) > 0 ? $ locales : [ $ collection -> mainLocale ] ; if ( $ useMainLocale && $ collection -> alwaysAvailable ) { $ locales [ ] = $ collection -> mainLocale ; } $ validLocales = array_unique ( array_intersect ( $ locales , $ collection -> availableLocales ) ) ; if ( count ( $ validLocales ) === 0 ) { throw new NotFoundException ( 'collection' , $ collection -> id ) ; } $ collectionData = [ 'id' => $ collection -> id , 'status' => $ collection -> status , 'offset' => $ collection -> offset , 'limit' => $ collection -> limit , 'items' => new LazyCollection ( function ( ) use ( $ collection ) : array { return array_map ( function ( PersistenceItem $ item ) : Item { return $ this -> mapItem ( $ item ) ; } , $ this -> collectionHandler -> loadCollectionItems ( $ collection ) ) ; } ) , 'query' => function ( ) use ( $ collection , $ locales ) : ? Query { try { $ persistenceQuery = $ this -> collectionHandler -> loadCollectionQuery ( $ collection ) ; } catch ( NotFoundException $ e ) { return null ; } return $ this -> mapQuery ( $ persistenceQuery , $ locales , false ) ; } , 'isTranslatable' => $ collection -> isTranslatable , 'mainLocale' => $ collection -> mainLocale , 'alwaysAvailable' => $ collection -> alwaysAvailable , 'availableLocales' => $ collection -> availableLocales , 'locale' => array_values ( $ validLocales ) [ 0 ] , ] ; return Collection :: fromArray ( $ collectionData ) ; }
Builds the API collection value from persistence one.

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

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

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