8000 [Form] Deprecate `searchAndRenderBlock` returning empty string · symfony/symfony@70840ed · GitHub
[go: up one dir, main page]

Skip to content

Commit 70840ed

Browse files
committed
[Form] Deprecate searchAndRenderBlock returning empty string
1 parent 57a1dd1 commit 70840ed

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

UPGRADE-4.2.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
UPGRADE FROM 4.1 to 4.2
22
=======================
33

4+
Form
5+
----
6+
7+
* Deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered.
8+
Instead of expecting such calls to return empty string, check if the field has already been rendered.
9+
10+
Before:
11+
```twig
12+
{% for field in fieldsWithPotentialDuplicates %}
13+
{{ form_widget(field) }}
14+
{% endfor %}
15+
```
16+
17+
After:
18+
```twig
19+
{% for field in fieldsWithPotentialDuplicates %}
20+
{% if not field.rendered %}
21+
{{ form_widget(field) }}
22+
{% endif %}
23+
{% endfor %}
24+
```
425
Security
526
--------
627

src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@
398398
{# Support #}
399399

400400
{%- block form_rows -%}
401-
{% for child in form %}
401+
{% for child in form if not child.rendered %}
402402
{{- form_row(child) -}}
403403
{% endfor %}
404404
{%- endblock form_rows -%}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<?php foreach ($form as $child) : ?>
2-
<?php echo $view['form']->row($child) ?>
2+
<?php if (!$view['form']->isRendered()): ?>
3+
<?php echo $view['form']->row($child) ?>
4+
<?php endif; ?>
35
<?php endforeach; ?>

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.2.0
5+
-----
6+
7+
* deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered
8+
49
4.1.0
510
-----
611

src/Symfony/Component/Form/FormRenderer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ public function searchAndRenderBlock(FormView $view, $blockNameSuffix, array $va
132132
$renderOnlyOnce = 'row' === $blockNameSuffix || 'widget' === $blockNameSuffix;
133133

134134
if ($renderOnlyOnce && $view->isRendered()) {
135+
// 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']));
135138
return '';
136139
}
137140

0 commit comments

Comments
 (0)
0