src/Menu/MenuConfigInterpreter.php
protected function mergeModulePresencesIntoLayoutLayer(array $layer, Collection $presencesPerModule)
    {
        $newLayer = [];

        foreach ($layer as $key => $value) {

            $stringKey = is_string($key) && ! is_numeric($key);

            if ($value instanceof MenuPresenceInterface && $value->type() == MenuPresenceType::GROUP) {
                $value->setChildren($this->mergeModulePresencesIntoLayoutLayer($value->children, $presencesPerModule));

                if ($stringKey) {
                    $newLayer[$key] = $value;
                } else {
                    $newLayer[] = $value;
                }
                continue;
            }

            if ( ! is_string($value)) {
                throw new UnexpectedValueException(
                    'Module key reference in menu layout must be string module key reference, or array for layout group'
                );
            }

            if (in_array($value, $this->assignedModuleKeys)) {
                throw new UnexpectedValueException(
                    "Module key reference '{$value}' for menu layout is used more than once."
                );
            }

            if ( ! $presencesPerModule->has($value)) {
                throw new UnexpectedValueException(
                    "Unknown (or disabled) module key reference '{$value}' in menu layout."
                );
            }

            $this->assignedModuleKeys[] = $value;

            foreach ($presences = $presencesPerModule->pull($value) as $presence) {
                $newLayer[] = $presence;
            }
        }

        return $newLayer;
    }
protected function mergeModulePresencesIntoLayoutLayer(array $layer, Collection $presencesPerModule)
    {
        $newLayer = [];

        foreach ($layer as $key => $value) {

            $stringKey = is_string($key) && ! is_numeric($key);

            if ($value instanceof MenuPresenceInterface && $value->type() == MenuPresenceType::GROUP) {
                $value->setChildren($this->mergeModulePresencesIntoLayoutLayer($value->children, $presencesPerModule));

                if ($stringKey) {
                    $newLayer[$key] = $value;
                } else {
                    $newLayer[] = $value;
                }
                continue;
            }

            if ( ! is_string($value)) {
                throw new UnexpectedValueException(
                    'Module key reference in menu layout must be string module key reference, or array for layout group'
                );
            }

            if (in_array($value, $this->assignedModuleKeys)) {
                throw new UnexpectedValueException(
                    "Module key reference '{$value}' for menu layout is used more than once."
                );
            }

            if ( ! $presencesPerModule->has($value)) {
                throw new UnexpectedValueException(
                    "Unknown (or disabled) module key reference '{$value}' in menu layout."
                );
            }

            $this->assignedModuleKeys[] = $value;

            foreach ($presences = $presencesPerModule->pull($value) as $presence) {
                $newLayer[] = $presence;
            }
        }

        return $newLayer;
    }
protected function mergeModulePresencesIntoLayoutLayer ( array $ layer , Collection $ presencesPerModule ) { $ newLayer = [ ] ; foreach ( $ layer as $ key => $ value ) { $ stringKey = is_string ( $ key ) && ! is_numeric ( $ key ) ; if ( $ value instanceof MenuPresenceInterface && $ value -> type ( ) == MenuPresenceType :: GROUP ) { $ value -> setChildren ( $ this -> mergeModulePresencesIntoLayoutLayer ( $ value -> children , $ presencesPerModule ) ) ; if ( $ stringKey ) { $ newLayer [ $ key ] = $ value ; } else { $ newLayer [ ] = $ value ; } continue ; } if ( ! is_string ( $ value ) ) { throw new UnexpectedValueException ( 'Module key reference in menu layout must be string module key reference, or array for layout group' ) ; } if ( in_array ( $ value , $ this -> assignedModuleKeys ) ) { throw new UnexpectedValueException ( "Module key reference '{$value}' for menu layout is used more than once." ) ; } if ( ! $ presencesPerModule -> has ( $ value ) ) { throw new UnexpectedValueException ( "Unknown (or disabled) module key reference '{$value}' in menu layout." ) ; } $ this -> assignedModuleKeys [ ] = $ value ; foreach ( $ presences = $ presencesPerModule -> pull ( $ value ) as $ presence ) { $ newLayer [ ] = $ presence ; } } return $ newLayer ; }
Merges module menu presences into layout tree layers recursively.

@param array      $layer
@param Collection $presencesPerModule    pulls presences per module if they are added to the layout
@return array
Merges module menu presences into layout tree layers recursively .