class FormErrorIterator implements RecursiveIterator, SeekableIterator, ArrayAccess, Countable
Iterates over the errors of a form.
Optionally, this class supports recursive iteration. In order to iterate recursively, set the constructor argument $deep to true. Now each element returned by the iterator is either an instance of {@link FormError} or of {@link FormErrorIterator}, in case the errors belong to a sub-form.
You can also wrap the iterator into a {@link \RecursiveIteratorIterator} to flatten the recursive structure into a flat list of errors.
INDENTATION | The prefix used for indenting nested error messages. |
__construct(FormInterface $form, array $errors) Creates a new iterator. | ||
string | __toString() Returns all iterated error messages as string. | |
FormInterface | getForm() Returns the iterated form. | |
FormError|FormErrorIterator | current() Returns the current element of the iterator. | |
next() Advances the iterator to the next position. | ||
int | key() Returns the current position of the iterator. | |
bool | valid() Returns whether the iterator's position is valid. | |
rewind() Sets the iterator's position to the beginning. | ||
bool | offsetExists(int $position) Returns whether a position exists in the iterator. | |
FormError|FormErrorIterator | offsetGet(int $position) Returns the element at a position in the iterator. | |
offsetSet($position, $value) Unsupported method. | ||
offsetUnset($position) Unsupported method. | ||
bool | hasChildren() Returns whether the current element of the iterator can be recursed into. | |
getChildren() Alias of {@link current()}. | ||
int | count() Returns the number of elements in the iterator. | |
seek(int $position) Sets the position of the iterator. | ||
FormErrorIterator | findByCodes(string|string[] $codes) Creates iterator for errors with specific codes. |
Creates a new iterator.
FormInterface | $form | The erroneous form |
array | $errors | The form errors |
InvalidArgumentException | If the errors are invalid |
Returns all iterated error messages as string.
string | The iterated error messages |
Returns the iterated form.
FormInterface | The form whose errors are iterated by this object |
Returns the current element of the iterator.
FormError|FormErrorIterator | an error or an iterator containing nested errors |
Advances the iterator to the next position.
Returns the current position of the iterator.
int | The 0-indexed position |
Returns whether the iterator's position is valid.
bool | Whether the iterator is valid |
Sets the iterator's position to the beginning.
This method detects if errors have been added to the form since the construction of the iterator.
Returns whether a position exists in the iterator.
int | $position | The position |
bool | Whether that position exists |
Returns the element at a position in the iterator.
int | $position | The position |
FormError|FormErrorIterator | The element at the given position |
OutOfBoundsException | If the given position does not exist |
Unsupported method.
$position | ||
$value |
BadMethodCallException |
Unsupported method.
$position |
BadMethodCallException |
Returns whether the current element of the iterator can be recursed into.
bool | Whether the current element is an instance of this class |
Alias of {@link current()}.
Returns the number of elements in the iterator.
Note that this is not the total number of errors, if the constructor parameter $deep was set to true! In that case, you should wrap the iterator into a {@link \RecursiveIteratorIterator} with the standard mode {@link \RecursiveIteratorIterator::LEAVES_ONLY} and count the result.
$iterator = new \RecursiveIteratorIterator($form->getErrors(true));
$count = count(iterator_to_array($iterator));
Alternatively, set the constructor argument $flatten to true as well.
$count = count($form->getErrors(true, true));
int | The number of iterated elements |
Sets the position of the iterator.
int | $position | The new position |
OutOfBoundsException | If the position is invalid |
Creates iterator for errors with specific codes.
string|string[] | $codes | The codes to find |
FormErrorIterator | new instance which contains only specific errors |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/Form/FormErrorIterator.html