protected function validateCreateOrUpdateForm($eventToDispatch, $log, $action, Coupon $model = null)
    {
        // Create the form from the request
        $couponForm = $this->getForm($action, $model);
        $response = null;
        $message = false;
        try {
            // Check the form against conditions violations
            $form = $this->validateForm($couponForm, 'POST');

            $couponEvent = $this->feedCouponCreateOrUpdateEvent($form, $model);

            // Dispatch Event to the Action
            $this->dispatch(
                $eventToDispatch,
                $couponEvent
            );

            $this->adminLogAppend(
                AdminResources::COUPON,
                AccessManager::UPDATE,
                sprintf(
                    'Coupon %s (ID ) ' . $log,
                    $couponEvent->getTitle(),
                    $couponEvent->getCouponModel()->getId()
                ),
                $couponEvent->getCouponModel()->getId()
            );

            if ($this->getRequest()->get('save_mode') == 'stay') {
                $response = RedirectResponse::create(str_replace(
                    '{id}',
                    $couponEvent->getCouponModel()->getId(),
                    $couponForm->getSuccessUrl()
                ));
            } else {
                // Redirect to the success URL
                $response = RedirectResponse::create(
                    URL::getInstance()->absoluteUrl($this->getRoute('admin.coupon.list'))
                );
            }
        } catch (FormValidationException $ex) {
            // Invalid data entered
            $message = $this->createStandardFormValidationErrorMessage($ex);
        } catch (\Exception $ex) {
            // Any other error
            $message = $this->getTranslator()->trans('Sorry, an error occurred: %err', ['%err' => $ex->getMessage()]);

            $this->logError($action, $message, $ex);
        }

        if ($message !== false) {
            // Mark the form as with error
            $couponForm->setErrorMessage($message);

            // Send the form and the error to the parser
            $this->getParserContext()
                ->addForm($couponForm)
                ->setGeneralError($message);
        }

        return $response;
    }
protected function validateCreateOrUpdateForm($eventToDispatch, $log, $action, Coupon $model = null)
    {
        // Create the form from the request
        $couponForm = $this->getForm($action, $model);
        $response = null;
        $message = false;
        try {
            // Check the form against conditions violations
            $form = $this->validateForm($couponForm, 'POST');

            $couponEvent = $this->feedCouponCreateOrUpdateEvent($form, $model);

            // Dispatch Event to the Action
            $this->dispatch(
                $eventToDispatch,
                $couponEvent
            );

            $this->adminLogAppend(
                AdminResources::COUPON,
                AccessManager::UPDATE,
                sprintf(
                    'Coupon %s (ID ) ' . $log,
                    $couponEvent->getTitle(),
                    $couponEvent->getCouponModel()->getId()
                ),
                $couponEvent->getCouponModel()->getId()
            );

            if ($this->getRequest()->get('save_mode') == 'stay') {
                $response = RedirectResponse::create(str_replace(
                    '{id}',
                    $couponEvent->getCouponModel()->getId(),
                    $couponForm->getSuccessUrl()
                ));
            } else {
                // Redirect to the success URL
                $response = RedirectResponse::create(
                    URL::getInstance()->absoluteUrl($this->getRoute('admin.coupon.list'))
                );
            }
        } catch (FormValidationException $ex) {
            // Invalid data entered
            $message = $this->createStandardFormValidationErrorMessage($ex);
        } catch (\Exception $ex) {
            // Any other error
            $message = $this->getTranslator()->trans('Sorry, an error occurred: %err', ['%err' => $ex->getMessage()]);

            $this->logError($action, $message, $ex);
        }

        if ($message !== false) {
            // Mark the form as with error
            $couponForm->setErrorMessage($message);

            // Send the form and the error to the parser
            $this->getParserContext()
                ->addForm($couponForm)
                ->setGeneralError($message);
        }

        return $response;
    }
protected function validateCreateOrUpdateForm ( $ eventToDispatch , $ log , $ action , Coupon $ model = null ) { // Create the form from the request $ couponForm = $ this -> getForm ( $ action , $ model ) ; $ response = null ; $ message = false ; try { // Check the form against conditions violations $ form = $ this -> validateForm ( $ couponForm , 'POST' ) ; $ couponEvent = $ this -> feedCouponCreateOrUpdateEvent ( $ form , $ model ) ; // Dispatch Event to the Action $ this -> dispatch ( $ eventToDispatch , $ couponEvent ) ; $ this -> adminLogAppend ( AdminResources :: COUPON , AccessManager :: UPDATE , sprintf ( 'Coupon %s (ID ) ' . $ log , $ couponEvent -> getTitle ( ) , $ couponEvent -> getCouponModel ( ) -> getId ( ) ) , $ couponEvent -> getCouponModel ( ) -> getId ( ) ) ; if ( $ this -> getRequest ( ) -> get ( 'save_mode' ) == 'stay' ) { $ response = RedirectResponse :: create ( str_replace ( '{id}' , $ couponEvent -> getCouponModel ( ) -> getId ( ) , $ couponForm -> getSuccessUrl ( ) ) ) ; } else { // Redirect to the success URL $ response = RedirectResponse :: create ( URL :: getInstance ( ) -> absoluteUrl ( $ this -> getRoute ( 'admin.coupon.list' ) ) ) ; } } catch ( FormValidationException $ ex ) { // Invalid data entered $ message = $ this -> createStandardFormValidationErrorMessage ( $ ex ) ; } catch ( \ Exception $ ex ) { // Any other error $ message = $ this -> getTranslator ( ) -> trans ( 'Sorry, an error occurred: %err' , [ '%err' => $ ex -> getMessage ( ) ] ) ; $ this -> logError ( $ action , $ message , $ ex ) ; } if ( $ message !== false ) { // Mark the form as with error $ couponForm -> setErrorMessage ( $ message ) ; // Send the form and the error to the parser $ this -> getParserContext ( ) -> addForm ( $ couponForm ) -> setGeneralError ( $ message ) ; } return $ response ; }
Validate the CreateOrUpdate form

@param string $eventToDispatch Event which will activate actions
@param string $log             created|edited
@param string $action          creation|edition
@param Coupon $model           Model if in update mode

@return $this
Validate the CreateOrUpdate form