8000 minor #31704 [Form] Throw exception when render a field which was alr… · symfony/symfony@8401f27 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8401f27

Browse files
minor #31704 [Form] Throw exception when render a field which was already rendered (yceruto)
This PR was merged into the 5.0-dev branch. Discussion ---------- [Form] Throw exception when render a field which was already rendered | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - See #27247 Commits ------- d1bbad0 Throw exception when render a field which was already rendered
2 parents bb9cf60 + d1bbad0 commit 8401f27

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* removed the `ChoiceLoaderInterface` implementation in `CountryType`, `LanguageType`, `LocaleType` and `CurrencyType`
88
* removed `getExtendedType()` method of the `FormTypeExtensionInterface`
99
* added static `getExtendedTypes()` method to the `FormTypeExtensionInterface`
10+
* calling to `FormRenderer::searchAndRenderBlock()` method for fields which were already rendered throw a `BadMethodCallException`
1011

1112
4.3.0
1213
-----

src/Symfony/Component/Form/FormRenderer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ public function searchAndRenderBlock(FormView $view, $blockNameSuffix, array $va
133133

134134
if ($renderOnlyOnce && $view->isRendered()) {
135135
// This is not allowed, because it would result in rendering same IDs multiple times, which is not valid.
136-
@trigger_error(sprintf('You are calling "form_%s" for field "%s" which has already been rendered before, trying to render fields which were already rendered is deprecated since Symfony 4.2 and will throw an exception in 5.0.', $blockNameSuffix, $view->vars['name']), E_USER_DEPRECATED);
137-
// throw new BadMethodCallException(sprintf('Field "%s" has already been rendered. Save result of previous render call to variable and output that instead.', $view->vars['name']));
138-
return '';
136+
throw new BadMethodCallException(sprintf('Field "%s" has already been rendered, save the result of previous render call to a variable and output that instead.', $view->vars['name']));
139137
}
140138

141139
// The cache key for storing the variables and types

src/Symfony/Compo 8000 nent/Form/Tests/FormRendererTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\Form\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Form\FormRenderer;
16+
use Symfony\Component\Form\FormView;
1517

1618
class FormRendererTest extends TestCase
1719
{
@@ -26,4 +28,19 @@ public function testHumanize()
2628
$this->assertEquals('Is active', $renderer->humanize('is_active'));
2729
$this->assertEquals('Is active', $renderer->humanize('isActive'));
2830
}
31+
32+
/**
33+
* @expectedException \Symfony\Component\Form\Exception\BadMethodCallException
34+
* @expectedExceptionMessage Field "foo" has already been rendered, save the result of previous render call to a variable and output that instead.
35+
*/
36+
public function testRenderARenderedField()
37+
{
38+
$formView = new FormView();
39+
$formView->vars['name'] = 'foo';
40+
$formView->setRendered();
41+
42+
$engine = $this->getMockBuilder('Symfony\Component\Form\FormRendererEngineInterface')->getMock();
43+
$renderer = new FormRenderer($engine);
44+
$renderer->searchAndRenderBlock($formView, 'row');
45+
}
2946
}

0 commit comments

Comments
 (0)
0