src/Contao/View/Contao2BackendView/ActionHandler/CopyHandler.php
public function copy(EnvironmentInterface $environment, ModelIdInterface $modelId)
    {
        $this->guardNotEditOnly($environment->getDataDefinition(), $modelId);
        $this->guardIsCreatable($environment, $modelId);

        $dataProvider = $environment->getDataProvider();
        $model        = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));

        // We need to keep the original data here.
        $copyModel = $environment->getController()->createClonedModel($model);

        $eventDispatcher = $environment->getEventDispatcher();
        // Dispatch pre duplicate event.
        $preCopyEvent = new PreDuplicateModelEvent($environment, $copyModel, $model);
        $eventDispatcher->dispatch($preCopyEvent::NAME, $preCopyEvent);

        // Save the copy.
        $environment->getDataProvider($copyModel->getProviderName())->save($copyModel);

        // Dispatch post duplicate event.
        $postCopyEvent = new PostDuplicateModelEvent($environment, $copyModel, $model);
        $eventDispatcher->dispatch($postCopyEvent::NAME, $postCopyEvent);

        return $copyModel;
    }
public function copy(EnvironmentInterface $environment, ModelIdInterface $modelId)
    {
        $this->guardNotEditOnly($environment->getDataDefinition(), $modelId);
        $this->guardIsCreatable($environment, $modelId);

        $dataProvider = $environment->getDataProvider();
        $model        = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));

        // We need to keep the original data here.
        $copyModel = $environment->getController()->createClonedModel($model);

        $eventDispatcher = $environment->getEventDispatcher();
        // Dispatch pre duplicate event.
        $preCopyEvent = new PreDuplicateModelEvent($environment, $copyModel, $model);
        $eventDispatcher->dispatch($preCopyEvent::NAME, $preCopyEvent);

        // Save the copy.
        $environment->getDataProvider($copyModel->getProviderName())->save($copyModel);

        // Dispatch post duplicate event.
        $postCopyEvent = new PostDuplicateModelEvent($environment, $copyModel, $model);
        $eventDispatcher->dispatch($postCopyEvent::NAME, $postCopyEvent);

        return $copyModel;
    }
public function copy ( EnvironmentInterface $ environment , ModelIdInterface $ modelId ) { $ this -> guardNotEditOnly ( $ environment -> getDataDefinition ( ) , $ modelId ) ; $ this -> guardIsCreatable ( $ environment , $ modelId ) ; $ dataProvider = $ environment -> getDataProvider ( ) ; $ model = $ dataProvider -> fetch ( $ dataProvider -> getEmptyConfig ( ) -> setId ( $ modelId -> getId ( ) ) ) ; // We need to keep the original data here. $ copyModel = $ environment -> getController ( ) -> createClonedModel ( $ model ) ; $ eventDispatcher = $ environment -> getEventDispatcher ( ) ; // Dispatch pre duplicate event. $ preCopyEvent = new PreDuplicateModelEvent ( $ environment , $ copyModel , $ model ) ; $ eventDispatcher -> dispatch ( $ preCopyEvent :: NAME , $ preCopyEvent ) ; // Save the copy. $ environment -> getDataProvider ( $ copyModel -> getProviderName ( ) ) -> save ( $ copyModel ) ; // Dispatch post duplicate event. $ postCopyEvent = new PostDuplicateModelEvent ( $ environment , $ copyModel , $ model ) ; $ eventDispatcher -> dispatch ( $ postCopyEvent :: NAME , $ postCopyEvent ) ; return $ copyModel ; }
Copy a model by using.

@param EnvironmentInterface $environment The environment.
@param ModelIdInterface     $modelId     The model id.

@return ModelInterface
Copy a model by using .