src/Contao/View/Contao2BackendView/ActionHandler/MultipleHandler/PasteAllHandler.php
protected function setSubItemsToCollection(
        ItemInterface $previousItem,
        array $subClipboardItems,
        array $collection,
        EnvironmentInterface $environment
    ) {
        if (empty($subClipboardItems)) {
            return $collection;
        }

        $dataProvider   = $environment->getDataProvider();
        $dataDefinition = $environment->getDataDefinition();
        $relationShip   = $dataDefinition->getModelRelationshipDefinition();
        $childCondition = $relationShip->getChildCondition($dataDefinition->getName(), $dataDefinition->getName());

        $previousModelId = $previousItem->getModelId();

        $intoItem = null;
        foreach ($subClipboardItems as $subClipboardItem) {
            $modelId = $subClipboardItem->getModelId();

            $pasteAfter =
                $intoItem ? $intoItem->getModelId()->getSerialized() : $previousModelId->getSerialized();

            $intoItem = $subClipboardItem;

            $collection[$modelId->getSerialized()] = [
                'item'       => $subClipboardItem,
                'pasteAfter' => $pasteAfter,
                'pasteMode'  => $intoItem ? 'after' : 'into'
            ];

            $model          =
                $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));
            $itemCollection =
                $dataProvider->fetchAll($dataProvider->getEmptyConfig()->setFilter($childCondition->getFilter($model)));

            if ($itemCollection) {
                $collection = $this->setSubItemsToCollection(
                    $subClipboardItem,
                    $this->getSubClipboardItems($this->getClipboardItems($environment), $itemCollection),
                    $collection,
                    $environment
                );
            }
        }

        return $collection;
    }
protected function setSubItemsToCollection(
        ItemInterface $previousItem,
        array $subClipboardItems,
        array $collection,
        EnvironmentInterface $environment
    ) {
        if (empty($subClipboardItems)) {
            return $collection;
        }

        $dataProvider   = $environment->getDataProvider();
        $dataDefinition = $environment->getDataDefinition();
        $relationShip   = $dataDefinition->getModelRelationshipDefinition();
        $childCondition = $relationShip->getChildCondition($dataDefinition->getName(), $dataDefinition->getName());

        $previousModelId = $previousItem->getModelId();

        $intoItem = null;
        foreach ($subClipboardItems as $subClipboardItem) {
            $modelId = $subClipboardItem->getModelId();

            $pasteAfter =
                $intoItem ? $intoItem->getModelId()->getSerialized() : $previousModelId->getSerialized();

            $intoItem = $subClipboardItem;

            $collection[$modelId->getSerialized()] = [
                'item'       => $subClipboardItem,
                'pasteAfter' => $pasteAfter,
                'pasteMode'  => $intoItem ? 'after' : 'into'
            ];

            $model          =
                $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));
            $itemCollection =
                $dataProvider->fetchAll($dataProvider->getEmptyConfig()->setFilter($childCondition->getFilter($model)));

            if ($itemCollection) {
                $collection = $this->setSubItemsToCollection(
                    $subClipboardItem,
                    $this->getSubClipboardItems($this->getClipboardItems($environment), $itemCollection),
                    $collection,
                    $environment
                );
            }
        }

        return $collection;
    }
protected function setSubItemsToCollection ( ItemInterface $ previousItem , array $ subClipboardItems , array $ collection , EnvironmentInterface $ environment ) { if ( empty ( $ subClipboardItems ) ) { return $ collection ; } $ dataProvider = $ environment -> getDataProvider ( ) ; $ dataDefinition = $ environment -> getDataDefinition ( ) ; $ relationShip = $ dataDefinition -> getModelRelationshipDefinition ( ) ; $ childCondition = $ relationShip -> getChildCondition ( $ dataDefinition -> getName ( ) , $ dataDefinition -> getName ( ) ) ; $ previousModelId = $ previousItem -> getModelId ( ) ; $ intoItem = null ; foreach ( $ subClipboardItems as $ subClipboardItem ) { $ modelId = $ subClipboardItem -> getModelId ( ) ; $ pasteAfter = $ intoItem ? $ intoItem -> getModelId ( ) -> getSerialized ( ) : $ previousModelId -> getSerialized ( ) ; $ intoItem = $ subClipboardItem ; $ collection [ $ modelId -> getSerialized ( ) ] = [ 'item' => $ subClipboardItem , 'pasteAfter' => $ pasteAfter , 'pasteMode' => $ intoItem ? 'after' : 'into' ] ; $ model = $ dataProvider -> fetch ( $ dataProvider -> getEmptyConfig ( ) -> setId ( $ modelId -> getId ( ) ) ) ; $ itemCollection = $ dataProvider -> fetchAll ( $ dataProvider -> getEmptyConfig ( ) -> setFilter ( $ childCondition -> getFilter ( $ model ) ) ) ; if ( $ itemCollection ) { $ collection = $ this -> setSubItemsToCollection ( $ subClipboardItem , $ this -> getSubClipboardItems ( $ this -> getClipboardItems ( $ environment ) , $ itemCollection ) , $ collection , $ environment ) ; } } return $ collection ; }
Set the sub items to the collection.

@param ItemInterface        $previousItem      The previous item.
@param array                $subClipboardItems The sub clipboard items.
@param array                $collection        The collection.
@param EnvironmentInterface $environment       The environment.

@return array
Set the sub items to the collection .