[Form] Changed the default value of $flatten in Form::getErrors() to true
This commit is contained in:
parent
a9268c4a99
commit
6b3fbb5905
|
@ -41,6 +41,6 @@ Form
|
|||
After:
|
||||
|
||||
```
|
||||
public function getErrors($deep = false, $flatten = false)
|
||||
public function getErrors($deep = false, $flatten = true)
|
||||
{
|
||||
```
|
||||
|
|
|
@ -181,8 +181,8 @@ UPGRADE FROM 2.x to 3.0
|
|||
and "csrf_token_id".
|
||||
|
||||
* The method `Form::getErrorsAsString()` was removed. Use `Form::getErrors()`
|
||||
instead with the argument `$deep` set to true and cast the returned iterator
|
||||
to a string (if not done implicitly by PHP).
|
||||
instead with the argument `$deep` set to true and `$flatten` set to false
|
||||
and cast the returned iterator to a string (if not done implicitly by PHP).
|
||||
|
||||
Before:
|
||||
|
||||
|
@ -193,7 +193,7 @@ UPGRADE FROM 2.x to 3.0
|
|||
After:
|
||||
|
||||
```
|
||||
echo $form->getErrors(true);
|
||||
echo $form->getErrors(true, false);
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -184,7 +184,7 @@ class Button implements \IteratorAggregate, FormInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getErrors($deep = false, $flatten = false)
|
||||
public function getErrors($deep = false, $flatten = true)
|
||||
{
|
||||
$errors = array();
|
||||
|
||||
|
|
|
@ -778,7 +778,7 @@ class Form implements \IteratorAggregate, FormInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getErrors($deep = false, $flatten = false)
|
||||
public function getErrors($deep = false, $flatten = true)
|
||||
{
|
||||
return new FormErrorIterator($this->errors, $this, $deep, $flatten);
|
||||
}
|
||||
|
@ -797,7 +797,7 @@ class Form implements \IteratorAggregate, FormInterface
|
|||
*/
|
||||
public function getErrorsAsString($level = 0)
|
||||
{
|
||||
return self::indent((string) $this->getErrors(true), $level);
|
||||
return self::indent((string) $this->getErrors(true, false), $level);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -68,7 +68,7 @@ class FormErrorIterator implements \RecursiveIterator, \SeekableIterator, \Array
|
|||
* @param Boolean $flatten Whether to flatten the recursive list of
|
||||
* errors into a flat list
|
||||
*/
|
||||
public function __construct(array &$errors, FormInterface $form, $deep = false, $flatten = false)
|
||||
public function __construct(array &$errors, FormInterface $form, $deep = false, $flatten = true)
|
||||
{
|
||||
$this->errors = &$errors;
|
||||
$this->form = $form;
|
||||
|
|
|
@ -104,7 +104,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
|
|||
* @since 2.5 Since version 2.5 this method returns a
|
||||
* {@link FormErrorIterator} instance instead of an array
|
||||
*/
|
||||
public function getErrors($deep = false, $flatten = false);
|
||||
public function getErrors($deep = false, $flatten = true);
|
||||
|
||||
/**
|
||||
* Updates the form with default data.
|
||||
|
|
|
@ -872,6 +872,30 @@ class CompoundFormTest extends AbstractFormTest
|
|||
|
||||
$errors = $this->form->getErrors(true);
|
||||
|
||||
$this->assertSame(
|
||||
"ERROR: Error 1\n".
|
||||
"ERROR: Error 2\n".
|
||||
"ERROR: Nested Error\n",
|
||||
(string) $errors
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
array($error1, $error2, $nestedError),
|
||||
iterator_to_array($errors)
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetErrorsDeepRecursive()
|
||||
{
|
||||
$this->form->addError($error1 = new FormError('Error 1'));
|
||||
$this->form->addError($error2 = new FormError('Error 2'));
|
||||
|
||||
$childForm = $this->getBuilder('Child')->getForm();
|
||||
$childForm->addError($nestedError = new FormError('Nested Error'));
|
||||
$this->form->add($childForm);
|
||||
|
||||
$errors = $this->form->getErrors(true, false);
|
||||
|
||||
$this->assertSame(
|
||||
"ERROR: Error 1\n".
|
||||
"ERROR: Error 2\n".
|
||||
|
@ -892,30 +916,6 @@ class CompoundFormTest extends AbstractFormTest
|
|||
$this->assertSame($nestedError, $nestedErrorsAsArray[0]);
|
||||
}
|
||||
|
||||
public function testGetErrorsDeepFlat()
|
||||
{
|
||||
$this->form->addError($error1 = new FormError('Error 1'));
|
||||
$this->form->addError($error2 = new FormError('Error 2'));
|
||||
|
||||
$childForm = $this->getBuilder('Child')->getForm();
|
||||
$childForm->addError($nestedError = new FormError('Nested Error'));
|
||||
$this->form->add($childForm);
|
||||
|
||||
$errors = $this->form->getErrors(true, true);
|
||||
|
||||
$this->assertSame(
|
||||
"ERROR: Error 1\n".
|
||||
"ERROR: Error 2\n".
|
||||
"ERROR: Nested Error\n",
|
||||
(string) $errors
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
array($error1, $error2, $nestedError),
|
||||
iterator_to_array($errors)
|
||||
);
|
||||
}
|
||||
|
||||
// Basic cases are covered in SimpleFormTest
|
||||
public function testCreateViewWithChildren()
|
||||
{
|
||||
|
|
Reference in New Issue