src/Contao/View/Contao2BackendView/EditMask.php
protected function doPersist()
    {
        $environment   = $this->getEnvironment();
        $dataProvider  = $environment->getDataProvider($this->model->getProviderName());
        $inputProvider = $environment->getInputProvider();

        if (!$this->model->getMeta(ModelInterface::IS_CHANGED)) {
            return true;
        }

        $this->handlePrePersist();

        if ((null === $this->model->getId()) && $this->getManualSortingProperty()) {
            $models = $dataProvider->getEmptyCollection();
            $models->push($this->model);

            $controller = $environment->getController();

            if ($inputProvider->hasParameter('after')) {
                $after = ModelId::fromSerialized($inputProvider->getParameter('after'));

                $previousDataProvider = $environment->getDataProvider($after->getDataProviderName());
                $previousFetchConfig  = $previousDataProvider->getEmptyConfig();
                $previousFetchConfig->setId($after->getId());
                $previousModel = $previousDataProvider->fetch($previousFetchConfig);

                if ($previousModel) {
                    $controller->pasteAfter($previousModel, $models, $this->getManualSortingProperty());
                } else {
                    $controller->pasteTop($models, $this->getManualSortingProperty());
                }
            } elseif ($inputProvider->hasParameter('into')) {
                $into = ModelId::fromSerialized($inputProvider->getParameter('into'));

                $parentDataProvider = $environment->getDataProvider($into->getDataProviderName());
                $parentFetchConfig  = $parentDataProvider->getEmptyConfig();
                $parentFetchConfig->setId($into->getId());
                $parentModel = $parentDataProvider->fetch($parentFetchConfig);

                if ($parentModel) {
                    $controller->pasteInto($parentModel, $models, $this->getManualSortingProperty());
                } else {
                    $controller->pasteTop($models, $this->getManualSortingProperty());
                }
            } else {
                $controller->pasteTop($models, $this->getManualSortingProperty());
            }

            $environment->getClipboard()->clear()->saveTo($environment);
        } else {
            if (!$this->allValuesUnique()) {
                return false;
            }
            $editInformation = $GLOBALS['container']['dc-general.edit-information'];

            // Save the model.
            $dataProvider->save($this->model, $editInformation->uniformTime());
        }

        $this->handlePostPersist();

        $this->storeVersion($this->model);

        return true;
    }
protected function doPersist()
    {
        $environment   = $this->getEnvironment();
        $dataProvider  = $environment->getDataProvider($this->model->getProviderName());
        $inputProvider = $environment->getInputProvider();

        if (!$this->model->getMeta(ModelInterface::IS_CHANGED)) {
            return true;
        }

        $this->handlePrePersist();

        if ((null === $this->model->getId()) && $this->getManualSortingProperty()) {
            $models = $dataProvider->getEmptyCollection();
            $models->push($this->model);

            $controller = $environment->getController();

            if ($inputProvider->hasParameter('after')) {
                $after = ModelId::fromSerialized($inputProvider->getParameter('after'));

                $previousDataProvider = $environment->getDataProvider($after->getDataProviderName());
                $previousFetchConfig  = $previousDataProvider->getEmptyConfig();
                $previousFetchConfig->setId($after->getId());
                $previousModel = $previousDataProvider->fetch($previousFetchConfig);

                if ($previousModel) {
                    $controller->pasteAfter($previousModel, $models, $this->getManualSortingProperty());
                } else {
                    $controller->pasteTop($models, $this->getManualSortingProperty());
                }
            } elseif ($inputProvider->hasParameter('into')) {
                $into = ModelId::fromSerialized($inputProvider->getParameter('into'));

                $parentDataProvider = $environment->getDataProvider($into->getDataProviderName());
                $parentFetchConfig  = $parentDataProvider->getEmptyConfig();
                $parentFetchConfig->setId($into->getId());
                $parentModel = $parentDataProvider->fetch($parentFetchConfig);

                if ($parentModel) {
                    $controller->pasteInto($parentModel, $models, $this->getManualSortingProperty());
                } else {
                    $controller->pasteTop($models, $this->getManualSortingProperty());
                }
            } else {
                $controller->pasteTop($models, $this->getManualSortingProperty());
            }

            $environment->getClipboard()->clear()->saveTo($environment);
        } else {
            if (!$this->allValuesUnique()) {
                return false;
            }
            $editInformation = $GLOBALS['container']['dc-general.edit-information'];

            // Save the model.
            $dataProvider->save($this->model, $editInformation->uniformTime());
        }

        $this->handlePostPersist();

        $this->storeVersion($this->model);

        return true;
    }
protected function doPersist ( ) { $ environment = $ this -> getEnvironment ( ) ; $ dataProvider = $ environment -> getDataProvider ( $ this -> model -> getProviderName ( ) ) ; $ inputProvider = $ environment -> getInputProvider ( ) ; if ( ! $ this -> model -> getMeta ( ModelInterface :: IS_CHANGED ) ) { return true ; } $ this -> handlePrePersist ( ) ; if ( ( null === $ this -> model -> getId ( ) ) && $ this -> getManualSortingProperty ( ) ) { $ models = $ dataProvider -> getEmptyCollection ( ) ; $ models -> push ( $ this -> model ) ; $ controller = $ environment -> getController ( ) ; if ( $ inputProvider -> hasParameter ( 'after' ) ) { $ after = ModelId :: fromSerialized ( $ inputProvider -> getParameter ( 'after' ) ) ; $ previousDataProvider = $ environment -> getDataProvider ( $ after -> getDataProviderName ( ) ) ; $ previousFetchConfig = $ previousDataProvider -> getEmptyConfig ( ) ; $ previousFetchConfig -> setId ( $ after -> getId ( ) ) ; $ previousModel = $ previousDataProvider -> fetch ( $ previousFetchConfig ) ; if ( $ previousModel ) { $ controller -> pasteAfter ( $ previousModel , $ models , $ this -> getManualSortingProperty ( ) ) ; } else { $ controller -> pasteTop ( $ models , $ this -> getManualSortingProperty ( ) ) ; } } elseif ( $ inputProvider -> hasParameter ( 'into' ) ) { $ into = ModelId :: fromSerialized ( $ inputProvider -> getParameter ( 'into' ) ) ; $ parentDataProvider = $ environment -> getDataProvider ( $ into -> getDataProviderName ( ) ) ; $ parentFetchConfig = $ parentDataProvider -> getEmptyConfig ( ) ; $ parentFetchConfig -> setId ( $ into -> getId ( ) ) ; $ parentModel = $ parentDataProvider -> fetch ( $ parentFetchConfig ) ; if ( $ parentModel ) { $ controller -> pasteInto ( $ parentModel , $ models , $ this -> getManualSortingProperty ( ) ) ; } else { $ controller -> pasteTop ( $ models , $ this -> getManualSortingProperty ( ) ) ; } } else { $ controller -> pasteTop ( $ models , $ this -> getManualSortingProperty ( ) ) ; } $ environment -> getClipboard ( ) -> clear ( ) -> saveTo ( $ environment ) ; } else { if ( ! $ this -> allValuesUnique ( ) ) { return false ; } $ editInformation = $ GLOBALS [ 'container' ] [ 'dc-general.edit-information' ] ; // Save the model. $ dataProvider -> save ( $ this -> model , $ editInformation -> uniformTime ( ) ) ; } $ this -> handlePostPersist ( ) ; $ this -> storeVersion ( $ this -> model ) ; return true ; }
Handle the persisting of the currently loaded model.

@return bool True means everything is okay, False error.

@SuppressWarnings(PHPMD.Superglobals)
Handle the persisting of the currently loaded model .