Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6362fa4

Browse files
mikeSimonsonfabpot
authored andcommitted
Button missing getErrorsAsString() fixes #8084 Debug: Not calling undefined method anymore. If the form contained a submit button the call would fail and the debug of the form wasn't possible. Now it will work in all cases. This fixes #8084
Adding a test for the fix of getErrorAsString on Form. Was throwing a fatal because of a method that did not exist on the new element type button.
1 parent 51014bf commit 6362fa4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Symfony/Component/Form/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ public function getErrorsAsString($level = 0)
751751

752752
foreach ($this->children as $key => $child) {
753753
$errors .= str_repeat(' ', $level).$key.":\n";
754-
if ($err = $child->getErrorsAsString($level + 4)) {
754+
if ($child instanceof self && $err = $child->getErrorsAsString($level + 4)) {
755755
$errors .= $err;
756756
} else {
757757
$errors .= str_repeat(' ', $level + 4)."No errors\n";

src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,20 @@ public function testPassZeroLabelToView()
571571
$this->assertSame('0', $view->vars['label']);
572572
}
573573

574+
public function testCanGetErrorsWhenButtonInForm()
575+
{
576+
$builder = $this->factory->createBuilder('form', null, array(
577+
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
578+
'required' => false,
579+
));
580+
$builder->add('foo', 'text');
581+
$builder->add('submit', 'submit');
582+
$form = $builder->getForm();
583+
584+
//This method should not throw a Fatal Error Exception.
585+
$form->getErrorsAsString();
586+
}
587+
574588
protected function getTestedType()
575589
{
576590
return 'form';

0 commit comments

Comments
 (0)