addError() public method

Adds an error to the field.
See also: FieldInterface
public addError ( Symfony\Component\Form\FieldError $error, Symfony\Component\Form\PropertyPathIterator $pathIterator = null, $type = null )
$error Symfony\Component\Form\FieldError
$pathIterator Symfony\Component\Form\PropertyPathIterator
Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function addError(FieldError $error, PropertyPathIterator $pathIterator = null, $type = null)
 {
     if ($pathIterator !== null) {
         if ($type === self::FIELD_ERROR && $pathIterator->hasNext()) {
             $pathIterator->next();
             if ($pathIterator->isProperty() && $pathIterator->current() === 'fields') {
                 $pathIterator->next();
             }
             if ($this->has($pathIterator->current()) && !$this->get($pathIterator->current())->isHidden()) {
                 $this->get($pathIterator->current())->addError($error, $pathIterator, $type);
                 return;
             }
         } else {
             if ($type === self::DATA_ERROR) {
                 $iterator = new RecursiveFieldsWithPropertyPathIterator($this);
                 $iterator = new \RecursiveIteratorIterator($iterator);
                 foreach ($iterator as $field) {
                     if (null !== ($fieldPath = $field->getPropertyPath())) {
                         if ($fieldPath->getElement(0) === $pathIterator->current() && !$field->isHidden()) {
                             if ($pathIterator->hasNext()) {
                                 $pathIterator->next();
                             }
                             $field->addError($error, $pathIterator, $type);
                             return;
                         }
                     }
                 }
             }
         }
     }
     parent::addError($error);
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function addError(Error $error, PropertyPathIterator $pathIterator = null)
 {
     if (null !== $pathIterator) {
         if ($error instanceof FieldError && $pathIterator->hasNext()) {
             $pathIterator->next();
             if ($pathIterator->isProperty() && $pathIterator->current() === 'fields') {
                 $pathIterator->next();
             }
             if ($this->has($pathIterator->current()) && !$this->get($pathIterator->current())->isHidden()) {
                 $this->get($pathIterator->current())->addError($error, $pathIterator);
                 return;
             }
         } else {
             if ($error instanceof DataError) {
                 $iterator = new RecursiveFieldIterator($this);
                 $iterator = new \RecursiveIteratorIterator($iterator);
                 foreach ($iterator as $field) {
                     if (null !== ($fieldPath = $field->getPropertyPath())) {
                         if ($fieldPath->getElement(0) === $pathIterator->current() && !$field->isHidden()) {
                             if ($pathIterator->hasNext()) {
                                 $pathIterator->next();
                             }
                             $field->addError($error, $pathIterator);
                             return;
                         }
                     }
                 }
             }
         }
     }
     parent::addError($error);
 }
Exemplo n.º 3
0
 /**
  * {@inheritDoc}
  */
 public function addError($message, PropertyPath $path = null, $type = null)
 {
     if ($path !== null) {
         if ($type === self::FIELD_ERROR && $path->hasNext()) {
             $path->next();
             if ($this->has($path->getCurrent()) && !$this->get($path->getCurrent())->isHidden()) {
                 $this->get($path->getCurrent())->addError($message, $path, $type);
                 return;
             }
         } else {
             if ($type === self::DATA_ERROR) {
                 $iterator = new RecursiveFieldsWithPropertyPathIterator($this);
                 $iterator = new \RecursiveIteratorIterator($iterator);
                 foreach ($iterator as $field) {
                     if (null !== ($fieldPath = $field->getPropertyPath())) {
                         $fieldPath->rewind();
                         if ($fieldPath->getCurrent() === $path->getCurrent() && !$field->isHidden()) {
                             if ($path->hasNext()) {
                                 $path->next();
                             }
                             $field->addError($message, $path, $type);
                             return;
                         }
                     }
                 }
             }
         }
     }
     parent::addError($message);
 }