FormErrorIterator
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.
Constants
INDENTATION |
The prefix used for indenting nested error messages. |
Methods
Returns all iterated error messages as string.
Returns the iterated form.
Returns the current element of the iterator.
Advances the iterator to the next position.
Returns the current position of the iterator.
Returns whether the iterator's position is valid.
Sets the iterator's position to the beginning.
Returns whether a position exists in the iterator.
Returns the element at a position in the iterator.
Unsupported method.
Unsupported method.
Returns whether the current element of the iterator can be recursed into.
Alias of {@link current()}.
Returns the number of elements in the iterator.
Sets the position of the iterator.
Details
at line line 60
__construct(FormInterface $form, array $errors)
Creates a new iterator.
at line line 82
string
__toString()
Returns all iterated error messages as string.
at line line 104
FormInterface
getForm()
Returns the iterated form.
at line line 115
FormError|FormErrorIterator
current()
Returns the current element of the iterator.
at line line 123
next()
Advances the iterator to the next position.
at line line 133
int
key()
Returns the current position of the iterator.
at line line 143
bool
valid()
Returns whether the iterator's position is valid.
at line line 154
rewind()
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.
at line line 166
bool
offsetExists(int $position)
Returns whether a position exists in the iterator.
at line line 180
FormError|FormErrorIterator
offsetGet(int $position)
Returns the element at a position in the iterator.
at line line 194
offsetSet($position, $value)
Unsupported method.
at line line 204
offsetUnset($position)
Unsupported method.
at line line 215
bool
hasChildren()
Returns whether the current element of the iterator can be recursed into.
at line line 223
getChildren()
Alias of {@link current()}.
at line line 245
int
count()
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));
at line line 257
seek(int $position)
Sets the position of the iterator.