addError() public method

Adds an error to this form.
public addError ( FormError $error ) : Form
$error FormError
return Form The current form
Example #1
5
 public static function handleFlashErrors(SymfonyForm $form, $identifier)
 {
     $errors = self::$app['flashbag']->get('form.' . $identifier . '.errors');
     foreach ($errors as $error) {
         $form->addError(new FormError($error));
     }
 }
 /** -------------------------
  * Error handler for (repeated) driving orders
  *
  * Displays all errors on the top of the form as a list.
  *
  * @param array $errors
  * @param Form $form
  * @return mixed
  */
 protected function setErrorsInForm($errors, Form &$form)
 {
     $tr = $this->container->get('translator');
     foreach ($errors as $error) {
         $form->addError(new FormError($tr->trans($error)));
     }
     return count($errors);
 }
 /**
  * Submits the form data to the API and returns the edited event, false if there is an error or null
  * if it is held for moderation.
  *
  * Should an error occur will this method append an error message to the form's error collection.
  *
  * @param Form $form
  *
  * @return EventEntity|null|false
  */
 private function editEventUsingForm(Form $form)
 {
     $eventApi = $this->getEventApi();
     $values = $form->getData()->toArray();
     $result = false;
     try {
         $result = $eventApi->edit($values);
     } catch (\Exception $e) {
         $form->addError(new FormError('An error occurred while editing your event: ' . $e->getMessage()));
     }
     try {
         if (isset($_FILES['event']['error']['new_icon']) && $_FILES['event']['error']['new_icon'] == UPLOAD_ERR_OK) {
             $eventApi->uploadIcon($result->getImagesUri(), $_FILES['event']['tmp_name']['new_icon']);
         }
     } catch (\Exception $e) {
         $result = false;
         $error = $e->getMessage();
         $messages = json_decode($error);
         if ($messages) {
             $error = implode(', ', $messages);
         }
         $form->addError(new FormError("An error occurred while uploading your event icon: {$error}"));
     }
     return $result;
 }
Example #4
1
 public function isValid(\Symfony\Component\Form\Form &$form)
 {
     $viewData = $form->getViewData();
     //pour le champ hidden allFieldsAreThere de Revision
     if (!is_object($viewData) && 'allFieldsAreThere' == $form->getName()) {
         return true;
     }
     if ($viewData instanceof Revision) {
         /** @var DataField $dataField */
         $dataField = $viewData->getDatafield();
     } elseif ($viewData instanceof DataField) {
         /** @var DataField $dataField */
         $dataField = $viewData;
     } else {
         throw new \Exception("Unforeseen type of viewData");
     }
     if ($dataField->getFieldType() !== null && $dataField->getFieldType()->getType() !== null) {
         $dataFieldTypeClassName = $dataField->getFieldType()->getType();
         /** @var DataFieldType $dataFieldType */
         $dataFieldType = new $dataFieldTypeClassName();
     }
     $isValid = true;
     if (isset($dataFieldType) && $dataFieldType->isContainer()) {
         //If datafield is container or type is null => Container => Recursive
         $formChildren = $form->all();
         foreach ($formChildren as $child) {
             if ($child instanceof \Symfony\Component\Form\Form) {
                 $tempIsValid = $this->isValid($child);
                 //Recursive
                 $isValid = $isValid && $tempIsValid;
             }
         }
         if (!$isValid) {
             $form->addError(new FormError("At least one child is not valid!"));
         }
     }
     //   		$isValid = $isValid && $dataFieldType->isValid($dataField);
     if (isset($dataFieldType) && !$dataFieldType->isValid($dataField)) {
         $isValid = false;
         $form->addError(new FormError("This Field is not valid! " . $dataField->getMessages()[0]));
     }
     return $isValid;
 }
Example #5
1
 /**
  * @param Form   $form
  * @param object $contract
  * @return Form
  */
 public function setFormErrors($form, $contract)
 {
     if (isset($contract->errors->children) && ($errors = $contract->errors->children)) {
         foreach ($errors as $key => $error) {
             if (is_object($error) && isset($error->errors[0])) {
                 $form->addError(new FormError(isset($this->getErrorsMessage()[$key]) ? $this->getErrorsMessage()[$key] : 'Something is wrong'));
             }
         }
     } else {
         $form->addError(new FormError('Something is wrong'));
     }
     return $form;
 }
Example #6
0
 public function onUpdate(Controller $controller, Request $request, ActionCache $action, $object, Form $form)
 {
     if ($object->default_group || $object->trust_group) {
         $roles = $this->admin_loader->getRoleHierarchy();
         foreach ($object->getRoles() as $role) {
             if ('ROLE_ADMIN' === $role || isset($roles[$role]) && in_array('ROLE_ADMIN', $roles[$role])) {
                 $form->addError(new \Symfony\Component\Form\FormError($this->trans(".form.default_group.no_admin")));
                 return;
             }
         }
         if ($object->hasRole('ROLE_ADMIN')) {
         }
         if ($object->default_group && $object->trust_group) {
             $form->addError(new \Symfony\Component\Form\FormError($this->trans(".form.default_group.trust_default_conflict")));
             return;
         }
         $em = $this->getManager();
         $repo = $this->getRepository();
         $groups = $repo->findAll();
         foreach ($groups as $group) {
             if ($group->isEqual($object)) {
                 continue;
             }
             if ($object->default_group) {
                 if ($group->default_group) {
                     $group->default_group = false;
                     $em->persist($group);
                 }
             }
             if ($object->trust_group) {
                 if ($group->trust_group) {
                     $group->trust_group = false;
                     $em->persist($group);
                 }
             }
         }
     }
     parent::onUpdate($controller, $request, $action, $object, $form);
 }
Example #7
0
 /**
  * @param \Symfony\Component\Form\Form $form
  */
 public function registerUser_(\Symfony\Component\Form\Form $form)
 {
     /* @var Championship\EventBundle\Classes\Form\User\Register $userRegister */
     $userRegister = $form->getData();
     // save data
     $userLogin = new UserLogin();
     $userLogin->setLogin($userRegister->login);
     $userLogin->setAuthData($userRegister->password);
     $user = new User();
     $user->setNick($userRegister->nick);
     // user -> user_login
     $user->setUserLogin($userLogin);
     // user_login -> user
     $userLogin->setUser($user);
     // check unique
     if ($user->checkUnique($this->controller)) {
         $form->addError($this->addError('Not Unique Nick'));
         return false;
     }
     if ($userLogin->checkUnique($this->controller)) {
         $form->addError($this->addError('Not Unique login'));
         return false;
     }
     $event = NotificationClient::createEvent($userLogin->getLogin(), $userLogin->generateMessage(), 1);
     if (false === $event) {
         $form->addError($this->addError('Event not create'));
         return false;
     }
     $doctrine = $this->controller->getDoctrine()->getEntityManager();
     $doctrine->persist($event);
     $doctrine->persist($userLogin);
     $doctrine->persist($user);
     $doctrine->flush();
     //
     return true;
 }
Example #8
0
 /**
  * Adds the storage exceeded error in a form.
  *
  * @param Form $form
  * @param integer $filesize
  */
 public function addStorageExceededFormError(Form $form, $fileSize, Workspace $workspace)
 {
     $filesize = $this->ut->getRealFileSize($fileSize);
     //we want how many bites and well...
     $maxSize = $this->ut->getRealFileSize($workspace->getMaxStorageSize());
     //throw new \Exception($maxSize);
     $usedSize = $this->ut->getRealFileSize($this->container->get('claroline.manager.workspace_manager')->getUsedStorage($workspace));
     $storageLeft = $maxSize - $usedSize;
     $fileSize = $this->ut->formatFileSize($fileSize);
     $storageLeft = $this->ut->formatFileSize($storageLeft);
     $translator = $this->container->get('translator');
     $msg = $translator->trans('storage_limit_exceeded', array('%storageLeft%' => $storageLeft, '%fileSize%' => $fileSize), 'platform');
     $form->addError(new FormError($msg));
 }
Example #9
0
 /**
  * Submits the form data to the API and returns the edited event, false if there is an error or null
  * if it is held for moderation.
  *
  * Should an error occur will this method append an error message to the form's error collection.
  *
  * @param Form $form
  *
  * @return EventEntity|null|false
  */
 private function editEventUsingForm(Form $form)
 {
     $eventApi = $this->getEventApi();
     $values = $form->getData()->toArray();
     $result = false;
     try {
         $result = $eventApi->edit($values);
     } catch (\Exception $e) {
         $form->addError(new FormError('An error occurred while editing your event: ' . $e->getMessage()));
     }
     return $result;
 }
 /**
  * Adds the storage exceeded error in a form.
  *
  * @param Form $form
  * @param int  $filesize
  */
 public function addStorageExceededFormError(Form $form, $fileSize, Workspace $workspace)
 {
     $maxSize = $this->ut->getRealFileSize($workspace->getMaxStorageSize());
     $usedSize = $this->ut->getRealFileSize($this->container->get('claroline.manager.workspace_manager')->getUsedStorage($workspace));
     $storageLeft = $maxSize - $usedSize;
     $fileSize = $this->ut->formatFileSize($this->ut->getRealFileSize($fileSize));
     $storageLeft = $this->ut->formatFileSize($storageLeft);
     $translator = $this->container->get('translator');
     $msg = $translator->trans('storage_limit_exceeded', ['%storageLeft%' => $storageLeft, '%fileSize%' => $fileSize], 'platform');
     $form->addError(new FormError($msg));
 }
Example #11
-1
 public function checkForm4(Form $form, ValidatorInterface $validator, TranslatorInterface $translator)
 {
     if ($form->isValid()) {
         $this->a_total = $this->a_teramo_wb + $this->a_teramo_wob + $this->a_teramo_tent + $this->a_guilianova_tent + $this->a_restaurant + $this->a_teramo_hotel + $this->a_guilianova_hotel + $this->a_none;
         if ($this->a_total == null || trim($this->a_total) == '') {
             $form->addError(new FormError($translator->trans('FORM.ENROLLMENT.NOACCOMODATION', array(), 'club')));
         }
     }
     return $form->isValid();
 }
Example #12
-1
 public function testNestedFormErrors()
 {
     $dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $formConfig = $this->getMock('Symfony\\Component\\Form\\FormConfigInterface');
     $formConfig->expects($this->any())->method('getEventDispatcher')->will($this->returnValue($dispatcher));
     $formConfig->expects($this->any())->method('getModelTransformers')->will($this->returnValue(array()));
     $fooConfig = clone $formConfig;
     $fooConfig->expects($this->any())->method('getName')->will($this->returnValue('foo'));
     $form = new Form($fooConfig);
     $form->addError(new FormError('This is the form error'));
     $barConfig = clone $formConfig;
     $barConfig->expects($this->any())->method('getName')->will($this->returnValue('bar'));
     $child = new Form($barConfig);
     $child->addError(new FormError('Error of the child form'));
     $form->add($child);
     $this->assertEquals($this->getContent('nested_form_errors'), $this->serialize($form));
 }
Example #13
-1
 /**
  * @param Form $form
  */
 private function validateForm(Form $form)
 {
     foreach ($this->container->get('validator')->validate($form->getData()) as $error) {
         /* @var ConstraintViolation $error */
         $form->addError(new FormError(strtolower(preg_replace('/([A-Z])/', '_$1', $error->getPropertyPath()) . ': ' . $error->getMessage())));
     }
 }
Example #14
-1
 /**
  * @param \Symfony\Component\Form\Form $form
  */
 protected function hookValidationError($form)
 {
     $form->addError(new FormError($this->__('Hook validation failed!')));
 }
Example #15
-1
 public function testAddErrorMapsErrorsOntoFieldsInVirtualGroups()
 {
     $error = new DataError('Message');
     // path is expected to point at "address"
     $expectedPath = new PropertyPath('address');
     $expectedPathIterator = $expectedPath->getIterator();
     $field = $this->createMockField('address');
     $field->expects($this->any())->method('getPropertyPath')->will($this->returnValue(new PropertyPath('address')));
     $field->expects($this->once())->method('addError')->with($this->equalTo($error), $this->equalTo($expectedPathIterator));
     $form = new Form('author');
     $nestedForm = new Form('nested', array('virtual' => true));
     $nestedForm->add($field);
     $form->add($nestedForm);
     $path = new PropertyPath('address');
     $form->addError($error, $path->getIterator());
 }
 public function testNestedFormErrors()
 {
     $dispather = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $form = new Form('foo', $dispather);
     $form->addError(new FormError('This is the form error'));
     $child = new Form('bar', $dispather);
     $child->addError(new FormError('Error of the child form'));
     $form->add($child);
     $this->assertEquals($this->getContent('nested_form_errors'), $this->serialize($form));
 }
Example #17
-1
 public function testNestedFormErrors()
 {
     $dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $formConfigBuilder = new \Symfony\Component\Form\FormConfigBuilder('foo', null, $dispatcher);
     $formConfigBuilder->setCompound(true);
     $formConfigBuilder->setDataMapper($this->getMock('Symfony\\Component\\Form\\DataMapperInterface'));
     $fooConfig = $formConfigBuilder->getFormConfig();
     $form = new Form($fooConfig);
     $form->addError(new FormError('This is the form error'));
     $formConfigBuilder = new \Symfony\Component\Form\FormConfigBuilder('bar', null, $dispatcher);
     $barConfig = $formConfigBuilder->getFormConfig();
     $child = new Form($barConfig);
     $child->addError(new FormError('Error of the child form'));
     $form->add($child);
     $this->assertEquals($this->getContent('nested_form_errors'), $this->serialize($form));
 }
Example #18
-1
 /**
  * @param Form $form
  * @param Message $message
  * @return bool
  */
 public function handleMessage(Form $form, Message $message)
 {
     $errors = $this->get('symbb.core.message.manager')->sendMessage($message);
     if ($errors->count() == 0) {
         return true;
     } else {
         $form->addError(new FormError($errors));
     }
     return false;
 }