From 6362fa41b061ad1b0a6d26c9867712dbde42a4ac Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 11 Jun 2013 23:05:51 +0200 Subject: [PATCH] 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. --- src/Symfony/Component/Form/Form.php | 2 +- .../Tests/Extension/Core/Type/FormTypeTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index f7fa834b35..767232392c 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -751,7 +751,7 @@ class Form implements \IteratorAggregate, FormInterface foreach ($this->children as $key => $child) { $errors .= str_repeat(' ', $level).$key.":\n"; - if ($err = $child->getErrorsAsString($level + 4)) { + if ($child instanceof self && $err = $child->getErrorsAsString($level + 4)) { $errors .= $err; } else { $errors .= str_repeat(' ', $level + 4)."No errors\n"; diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php index cced82f4cf..60b6afa6c8 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php @@ -571,6 +571,20 @@ class FormTypeTest extends BaseTypeTest $this->assertSame('0', $view->vars['label']); } + public function testCanGetErrorsWhenButtonInForm() + { + $builder = $this->factory->createBuilder('form', null, array( + 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author', + 'required' => false, + )); + $builder->add('foo', 'text'); + $builder->add('submit', 'submit'); + $form = $builder->getForm(); + + //This method should not throw a Fatal Error Exception. + $form->getErrorsAsString(); + } + protected function getTestedType() { return 'form';