module/Paragraph/src/Grid/Paragraph/Controller/ContentController.php
public function editAction()
    {
        $params     = $this->params();
        $request    = $this->getRequest();
        $locator    = $this->getServiceLocator();
        $model      = $locator->get( 'Grid\Paragraph\Model\Paragraph\Model' )
                              ->setLocale( $this->getAdminLocale() );
        $form       = $locator->get( 'Form' )
                              ->create( 'Grid\Paragraph\Content' );

        if ( ( $id = $params->fromRoute( 'id' ) ) )
        {
            $paragraph = $model->find( $id );

            if ( empty( $paragraph ) )
            {
                $this->getResponse()
                     ->setStatusCode( 404 );

                return;
            }

            if ( ! $paragraph->isEditable() )
            {
                $this->getResponse()
                     ->setStatusCode( 403 );

                return;
            }
        }
        else
        {
            if ( ! $this->getPermissionsModel()
                        ->isAllowed( 'paragraph.content', 'create' ) )
            {
                $this->getResponse()
                     ->setStatusCode( 403 );

                return;
            }

            $userId = $this->getAuthenticationService()
                           ->getIdentity()
                           ->id;

            $paragraph = $model->create( array(
                'type'          => 'content',
                'created'       => time(),
                'userId'        => $userId,
                'editUsers'     => array( $userId ),
            ) );
        }

        /* @var $form \Zend\Form\Form */
        $form->setHydrator( $model->getMapper() )
             ->bind( $paragraph );

        if ( $request->isPost() )
        {
            $form->setData( $request->getPost() );

            if ( $form->isValid() && $paragraph->save() )
            {
                $this->messenger()
                     ->add( 'paragraph.form.content.success',
                            'paragraph', Message::LEVEL_INFO );

                return $this->redirect()
                            ->toRoute( 'Grid\Paragraph\Content\List', array(
                                'locale' => (string) $this->locale(),
                            ) );
            }
            else
            {
                $this->messenger()
                     ->add( 'paragraph.form.content.failed',
                            'paragraph', Message::LEVEL_ERROR );
            }
        }

        $form->setCancel(
            $this->url()
                 ->fromRoute( 'Grid\Paragraph\Content\List', array(
                        'locale' => (string) $this->locale(),
                    ) )
        );

        return array(
            'form'      => $form,
            'paragraph' => $paragraph,
        );
    }
public function editAction()
    {
        $params     = $this->params();
        $request    = $this->getRequest();
        $locator    = $this->getServiceLocator();
        $model      = $locator->get( 'Grid\Paragraph\Model\Paragraph\Model' )
                              ->setLocale( $this->getAdminLocale() );
        $form       = $locator->get( 'Form' )
                              ->create( 'Grid\Paragraph\Content' );

        if ( ( $id = $params->fromRoute( 'id' ) ) )
        {
            $paragraph = $model->find( $id );

            if ( empty( $paragraph ) )
            {
                $this->getResponse()
                     ->setStatusCode( 404 );

                return;
            }

            if ( ! $paragraph->isEditable() )
            {
                $this->getResponse()
                     ->setStatusCode( 403 );

                return;
            }
        }
        else
        {
            if ( ! $this->getPermissionsModel()
                        ->isAllowed( 'paragraph.content', 'create' ) )
            {
                $this->getResponse()
                     ->setStatusCode( 403 );

                return;
            }

            $userId = $this->getAuthenticationService()
                           ->getIdentity()
                           ->id;

            $paragraph = $model->create( array(
                'type'          => 'content',
                'created'       => time(),
                'userId'        => $userId,
                'editUsers'     => array( $userId ),
            ) );
        }

        /* @var $form \Zend\Form\Form */
        $form->setHydrator( $model->getMapper() )
             ->bind( $paragraph );

        if ( $request->isPost() )
        {
            $form->setData( $request->getPost() );

            if ( $form->isValid() && $paragraph->save() )
            {
                $this->messenger()
                     ->add( 'paragraph.form.content.success',
                            'paragraph', Message::LEVEL_INFO );

                return $this->redirect()
                            ->toRoute( 'Grid\Paragraph\Content\List', array(
                                'locale' => (string) $this->locale(),
                            ) );
            }
            else
            {
                $this->messenger()
                     ->add( 'paragraph.form.content.failed',
                            'paragraph', Message::LEVEL_ERROR );
            }
        }

        $form->setCancel(
            $this->url()
                 ->fromRoute( 'Grid\Paragraph\Content\List', array(
                        'locale' => (string) $this->locale(),
                    ) )
        );

        return array(
            'form'      => $form,
            'paragraph' => $paragraph,
        );
    }
public function editAction ( ) { $ params = $ this -> params ( ) ; $ request = $ this -> getRequest ( ) ; $ locator = $ this -> getServiceLocator ( ) ; $ model = $ locator -> get ( 'Grid\Paragraph\Model\Paragraph\Model' ) -> setLocale ( $ this -> getAdminLocale ( ) ) ; $ form = $ locator -> get ( 'Form' ) -> create ( 'Grid\Paragraph\Content' ) ; if ( ( $ id = $ params -> fromRoute ( 'id' ) ) ) { $ paragraph = $ model -> find ( $ id ) ; if ( empty ( $ paragraph ) ) { $ this -> getResponse ( ) -> setStatusCode ( 404 ) ; return ; } if ( ! $ paragraph -> isEditable ( ) ) { $ this -> getResponse ( ) -> setStatusCode ( 403 ) ; return ; } } else { if ( ! $ this -> getPermissionsModel ( ) -> isAllowed ( 'paragraph.content' , 'create' ) ) { $ this -> getResponse ( ) -> setStatusCode ( 403 ) ; return ; } $ userId = $ this -> getAuthenticationService ( ) -> getIdentity ( ) -> id ; $ paragraph = $ model -> create ( array ( 'type' => 'content' , 'created' => time ( ) , 'userId' => $ userId , 'editUsers' => array ( $ userId ) , ) ) ; } /* @var $form \Zend\Form\Form */ $ form -> setHydrator ( $ model -> getMapper ( ) ) -> bind ( $ paragraph ) ; if ( $ request -> isPost ( ) ) { $ form -> setData ( $ request -> getPost ( ) ) ; if ( $ form -> isValid ( ) && $ paragraph -> save ( ) ) { $ this -> messenger ( ) -> add ( 'paragraph.form.content.success' , 'paragraph' , Message :: LEVEL_INFO ) ; return $ this -> redirect ( ) -> toRoute ( 'Grid\Paragraph\Content\List' , array ( 'locale' => ( string ) $ this -> locale ( ) , ) ) ; } else { $ this -> messenger ( ) -> add ( 'paragraph.form.content.failed' , 'paragraph' , Message :: LEVEL_ERROR ) ; } } $ form -> setCancel ( $ this -> url ( ) -> fromRoute ( 'Grid\Paragraph\Content\List' , array ( 'locale' => ( string ) $ this -> locale ( ) , ) ) ) ; return array ( 'form' => $ form , 'paragraph' => $ paragraph , ) ; }
Edit a content
Edit a content