src/Sulu/Component/Media/SystemCollections/SystemCollectionManager.php
private function iterateOverCollections($children, $userId, $parent = null, $namespace = '')
    {
        $format = ('' !== $namespace ? '%s.%s' : '%s%s');
        $collections = [];
        foreach ($children as $collectionKey => $collectionItem) {
            $key = sprintf($format, $namespace, $collectionKey);
            $collections[$key] = $this->getOrCreateCollection(
                $key,
                $collectionItem['meta_title'],
                $userId,
                $parent
            )->getId();

            if (array_key_exists('collections', $collectionItem)) {
                $childCollections = $this->iterateOverCollections(
                    $collectionItem['collections'],
                    $userId,
                    $collections[$key],
                    $key
                );
                $collections = array_merge($collections, $childCollections);
            }
        }

        return $collections;
    }
private function iterateOverCollections($children, $userId, $parent = null, $namespace = '')
    {
        $format = ('' !== $namespace ? '%s.%s' : '%s%s');
        $collections = [];
        foreach ($children as $collectionKey => $collectionItem) {
            $key = sprintf($format, $namespace, $collectionKey);
            $collections[$key] = $this->getOrCreateCollection(
                $key,
                $collectionItem['meta_title'],
                $userId,
                $parent
            )->getId();

            if (array_key_exists('collections', $collectionItem)) {
                $childCollections = $this->iterateOverCollections(
                    $collectionItem['collections'],
                    $userId,
                    $collections[$key],
                    $key
                );
                $collections = array_merge($collections, $childCollections);
            }
        }

        return $collections;
    }
private function iterateOverCollections ( $ children , $ userId , $ parent = null , $ namespace = '' ) { $ format = ( '' !== $ namespace ? '%s.%s' : '%s%s' ) ; $ collections = [ ] ; foreach ( $ children as $ collectionKey => $ collectionItem ) { $ key = sprintf ( $ format , $ namespace , $ collectionKey ) ; $ collections [ $ key ] = $ this -> getOrCreateCollection ( $ key , $ collectionItem [ 'meta_title' ] , $ userId , $ parent ) -> getId ( ) ; if ( array_key_exists ( 'collections' , $ collectionItem ) ) { $ childCollections = $ this -> iterateOverCollections ( $ collectionItem [ 'collections' ] , $ userId , $ collections [ $ key ] , $ key ) ; $ collections = array_merge ( $ collections , $ childCollections ) ; } } return $ collections ; }
Iterates over an array of children collections, creates them.
This function is recursive!

@param $children
@param $userId
@param null $parent
@param string $namespace

@return array
Iterates over an array of children collections creates them . This function is recursive!