module/Paragraph/src/Grid/Paragraph/Controller/ContentController.php
public function cloneAction()
    {
        if ( ! $this->getPermissionsModel()
                    ->isAllowed( 'paragraph.content', 'create' ) )
        {
            $this->getResponse()
                 ->setStatusCode( 403 );

            return;
        }

        $params     = $this->params();
        $locator    = $this->getServiceLocator();
        $model      = $locator->get( 'Grid\Paragraph\Model\Paragraph\Model' )
                              ->setLocale( $this->getAdminLocale() );
        $paragraph  = $model->find( $params->fromRoute( 'id' ) );

        if ( empty( $paragraph ) || $paragraph->type !== 'content' )
        {
            $this->getResponse()
                 ->setStatusCode( 404 );

            return;
        }

        $cloneId = $model->cloneFrom( $paragraph->id );

        if ( $cloneId )
        {
            $clone = $model->find( $cloneId );

            if ( ! empty( $clone ) )
            {
                $userId = $this->getAuthenticationService()
                               ->getIdentity()
                               ->id;

                if ( empty( $clone->userId ) )
                {
                    $clone->userId = $userId;
                }

                if ( ! in_array( $userId, $clone->editUsers ) )
                {
                    $clone->editUsers = array_merge(
                        $clone->editUsers,
                        array( $userId )
                    );
                }

                $clone->name = rtrim( $clone->name ) . ' '
                             . $locator->get( 'Zork\I18n\Translator\Translator' )
                                       ->translate( 'default.cloned', 'default' );

                $clone->save();
            }

            $this->messenger()
                 ->add( 'paragraph.action.clone.success',
                        'paragraph', Message::LEVEL_INFO );
        }
        else
        {
            $this->messenger()
                 ->add( 'paragraph.action.clone.failed',
                        'paragraph', Message::LEVEL_ERROR );
        }

        return $this->redirect()
                    ->toRoute( 'Grid\Paragraph\Content\List', array(
                        'locale' => (string) $this->locale(),
                    ) );
    }
public function cloneAction()
    {
        if ( ! $this->getPermissionsModel()
                    ->isAllowed( 'paragraph.content', 'create' ) )
        {
            $this->getResponse()
                 ->setStatusCode( 403 );

            return;
        }

        $params     = $this->params();
        $locator    = $this->getServiceLocator();
        $model      = $locator->get( 'Grid\Paragraph\Model\Paragraph\Model' )
                              ->setLocale( $this->getAdminLocale() );
        $paragraph  = $model->find( $params->fromRoute( 'id' ) );

        if ( empty( $paragraph ) || $paragraph->type !== 'content' )
        {
            $this->getResponse()
                 ->setStatusCode( 404 );

            return;
        }

        $cloneId = $model->cloneFrom( $paragraph->id );

        if ( $cloneId )
        {
            $clone = $model->find( $cloneId );

            if ( ! empty( $clone ) )
            {
                $userId = $this->getAuthenticationService()
                               ->getIdentity()
                               ->id;

                if ( empty( $clone->userId ) )
                {
                    $clone->userId = $userId;
                }

                if ( ! in_array( $userId, $clone->editUsers ) )
                {
                    $clone->editUsers = array_merge(
                        $clone->editUsers,
                        array( $userId )
                    );
                }

                $clone->name = rtrim( $clone->name ) . ' '
                             . $locator->get( 'Zork\I18n\Translator\Translator' )
                                       ->translate( 'default.cloned', 'default' );

                $clone->save();
            }

            $this->messenger()
                 ->add( 'paragraph.action.clone.success',
                        'paragraph', Message::LEVEL_INFO );
        }
        else
        {
            $this->messenger()
                 ->add( 'paragraph.action.clone.failed',
                        'paragraph', Message::LEVEL_ERROR );
        }

        return $this->redirect()
                    ->toRoute( 'Grid\Paragraph\Content\List', array(
                        'locale' => (string) $this->locale(),
                    ) );
    }
public function cloneAction ( ) { if ( ! $ this -> getPermissionsModel ( ) -> isAllowed ( 'paragraph.content' , 'create' ) ) { $ this -> getResponse ( ) -> setStatusCode ( 403 ) ; return ; } $ params = $ this -> params ( ) ; $ locator = $ this -> getServiceLocator ( ) ; $ model = $ locator -> get ( 'Grid\Paragraph\Model\Paragraph\Model' ) -> setLocale ( $ this -> getAdminLocale ( ) ) ; $ paragraph = $ model -> find ( $ params -> fromRoute ( 'id' ) ) ; if ( empty ( $ paragraph ) || $ paragraph -> type !== 'content' ) { $ this -> getResponse ( ) -> setStatusCode ( 404 ) ; return ; } $ cloneId = $ model -> cloneFrom ( $ paragraph -> id ) ; if ( $ cloneId ) { $ clone = $ model -> find ( $ cloneId ) ; if ( ! empty ( $ clone ) ) { $ userId = $ this -> getAuthenticationService ( ) -> getIdentity ( ) -> id ; if ( empty ( $ clone -> userId ) ) { $ clone -> userId = $ userId ; } if ( ! in_array ( $ userId , $ clone -> editUsers ) ) { $ clone -> editUsers = array_merge ( $ clone -> editUsers , array ( $ userId ) ) ; } $ clone -> name = rtrim ( $ clone -> name ) . ' ' . $ locator -> get ( 'Zork\I18n\Translator\Translator' ) -> translate ( 'default.cloned' , 'default' ) ; $ clone -> save ( ) ; } $ this -> messenger ( ) -> add ( 'paragraph.action.clone.success' , 'paragraph' , Message :: LEVEL_INFO ) ; } else { $ this -> messenger ( ) -> add ( 'paragraph.action.clone.failed' , 'paragraph' , Message :: LEVEL_ERROR ) ; } return $ this -> redirect ( ) -> toRoute ( 'Grid\Paragraph\Content\List' , array ( 'locale' => ( string ) $ this -> locale ( ) , ) ) ; }
Clone a content
Clone a content