From dab0688b2bcb438b937dac5c2ee1088e7efd1254 Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 11 Jun 2013 23:05:51 +0200 Subject: [PATCH] [Form][BUG]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 35135274a703a..4f6834aad89ec 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -747,7 +747,7 @@ public function getErrorsAsString($level = 0) 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 cced82f4cf84a..60b6afa6c89c5 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 @@ public function testPassZeroLabelToView() $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';