8000 [Form] Changed the default value of $flatten in Form::getErrors() to … · symfony/symfony@6b3fbb5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b3fbb5

Browse files
committed
[Form] Changed the default value of $flatten in Form::getErrors() to true
1 parent a9268c4 commit 6b3fbb5

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

UPGRADE-2.5.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ Form
4141
After:
4242

4343
```
44-
public function getErrors($deep = false, $flatten = false)
44+
public function getErrors($deep = false, $flatten = true)
4545
{
4646
```

UPGRADE-3.0.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ UPGRADE FROM 2.x to 3.0
181181
and "csrf_token_id".
182182

183183
* The method `Form::getErrorsAsString()` was removed. Use `Form::getErrors()`
184-
instead with the argument `$deep` set to true and cast the returned iterator
185-
to a string (if not done implicitly by PHP).
184+
instead with the argument `$deep` se 8000 t to true and `$flatten` set to false
185+
and cast the returned iterator to a string (if not done implicitly by PHP).
186186

187187
Before:
188188

@@ -193,7 +193,7 @@ UPGRADE FROM 2.x to 3.0
193193
After:
194194

195195
```
196-
echo $form->getErrors(true);
196+
echo $form->getErrors(true, false);
197197
```
198198

199199

src/Symfony/Component/Form/Button.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function all()
184184
/**
185185
* {@inheritdoc}
186186
*/
187-
public function getErrors($deep = false, $flatten = false)
187+
public function getErrors($deep = false, $flatten = true)
188188
{
189189
$errors = array();
190190

src/Symfony/Component/Form/Form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ public function getClickedButton()
778778
/**
779779
* {@inheritdoc}
780780
*/
781-
public function getErrors($deep = false, $flatten = false)
781+
public function getErrors($deep = false, $flatten = true)
782782
{
783783
return new FormErrorIterator($this->errors, $this, $deep, $flatten);
784784
}
@@ -797,7 +797,7 @@ public function getErrors($deep = false, $flatten = false)
797797
*/
798798
public function getErrorsAsString($level = 0)
799799
{
800-
return self::indent((string) $this->getErrors(true), $level);
800+
return self::indent((string) $this->getErrors(true, false), $level);
801801
}
802802

803803
/**

src/Symfony/Component/Form/FormErrorIterator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class FormErrorIterator implements \RecursiveIterator, \SeekableIterator, \Array
6868
* @param Boolean $flatten Whether to flatten the recursive list of
6969
* errors into a flat list
7070
*/
71-
public function __construct(array &$errors, FormInterface $form, $deep = false, $flatten = false)
71+
public function __construct(array &$errors, FormInterface $form, $deep = false, $flatten = true)
7272
{
7373
$this->errors = &$errors;
7474
$this->form = $form;

src/Symfony/Component/Form/FormInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function all();
104104
* @since 2.5 Since version 2.5 this method returns a
105105
* {@link FormErrorIterator} instance instead of an array
106106
*/
107-
public function getErrors($deep = false, $flatten = false);
107+
public function getErrors($deep = false, $flatten = true);
108108

109109
/**
110110
* Updates the form with default data.

src/Symfony/Component/Form/Tests/CompoundFormTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -875,24 +875,17 @@ public function testGetErrorsDeep()
875875
$this->assertSame(
876876
"ERROR: Error 1\n".
877877
"ERROR: Error 2\n".
878-
"Child:\n".
879-
" ERROR: Nested Error\n",
878+
"ERROR: Nested Error\n",
880879
(string) $errors
881880
);
882881

883-
$errorsAsArray = iterator_to_array($errors);
884-
885-
$this->assertSame($error1, $errorsAsArray[0]);
886-
$this->assertSame($error2, $errorsAsArray[1]);
887-
$this->assertInstanceOf('Symfony\Component\Form\FormErrorIterator', $errorsAsArray[2]);
888-
889-
$nestedErrorsAsArray = iterator_to_array($errorsAsArray[2]);
890-
891-
$this->assertCount(1, $nestedErrorsAsArray);
892-
$this->assertSame($nestedError, $nestedErrorsAsArray[0]);
882+
$this->assertSame(
883+
array($error1, $error2, $nestedError),
884+
iterator_to_array($errors)
885+
);
893886
}
894887

895-
public function testGetErrorsDeepFlat()
888+
public function testGetErrorsDeepRecursive()
896889
{
897890
$this->form->addError($error1 = new FormError('Error 1'));
898891
$this->form->addError($error2 = new FormError('Error 2'));
@@ -901,19 +894,26 @@ public function testGetErrorsDeepFlat()
901894
$childForm->addError($nestedError = new FormError('Nested Error'));
902895
$this->form->add($childForm);
903896

904-
$errors = $this->form->getErrors(true, true);
897+
$errors = $this->form->getErrors(true, false);
905898

906899
$this->assertSame(
907900
"ERROR: Error 1\n".
908901
"ERROR: Error 2\n".
909-
"ERROR: Nested Error\n",
902+
"Child:\n".
903+
" ERROR: Nested Error\n",
910904
(string) $errors
911905
);
912906

913-
$this->assertSame(
914-
array($error1, $error2, $nestedError),
915-
iterator_to_array($errors)
916-
);
907+
$errorsAsArray = iterator_to_array($errors);
908+
909+
$this->assertSame($error1, $errorsAsArray[0]);
910+
$this->assertSame($error2, $errorsAsArray[1]);
911+
$this->assertInstanceOf('Symfony\Component\Form\FormErrorIterator', $errorsAsArray[2]);
912+
913+
$nestedErrorsAsArray = iterator_to_array($errorsAsArray[2]);
914+
915+
$this->assertCount(1, $nestedErrorsAsArray);
916+
$this->assertSame($nestedError, $nestedErrorsAsArray[0]);
917917
}
918918

919919
// Basic cases are covered in SimpleFormTest

0 commit comments

Comments
 (0)
0