Ejemplo n.º 1
0
 /**
  * Setup the error context when an error occurs in a action method.
  *
  * @param string     $action        the action that caused the error (category modification, variable creation, currency update, etc.)
  * @param BaseForm   $form          the form where the error occured, or null if no form was involved
  * @param string     $error_message the error message
  * @param \Exception $exception     the exception or null if no exception
  */
 protected function setupFormErrorContext($action, $error_message, BaseForm $form = null, \Exception $exception = null)
 {
     if ($error_message !== false) {
         // Log the error message
         Tlog::getInstance()->error($this->getTranslator()->trans("Error during %action process : %error. Exception was %exc", array('%action' => $action, '%error' => $error_message, '%exc' => $exception != null ? $exception->getMessage() : 'no exception')));
         if ($form != null) {
             // Mark the form as errored
             $form->setErrorMessage($error_message);
             // Pass it to the parser context
             $this->getParserContext()->addForm($form);
         }
         // Pass the error message to the parser.
         $this->getParserContext()->setGeneralError($error_message);
     }
 }
 /**
  * @param BaseForm $form
  * @param string $successMessage
  * @param string $errorMessage
  * @return \Thelia\Core\HttpFoundation\Response
  */
 protected function renderAdminConfig($form, $successMessage, $errorMessage)
 {
     if (!empty($errorMessage)) {
         $form->setErrorMessage($errorMessage);
         $this->getParserContext()->addForm($form)->setGeneralError($errorMessage);
     }
     //for compatibility 2.0
     if (method_exists($this->getSession(), "getFlashBag")) {
         if (empty($errorMessage)) {
             $this->getSession()->getFlashBag()->add("success", $successMessage);
         } else {
             $this->getSession()->getFlashBag()->add("danger", $errorMessage);
         }
     }
     return RedirectResponse::create(URL::getInstance()->absoluteUrl("/admin/module/CustomerFamily"));
 }