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

Skip to content

Commit 259ef8b

Browse files
committed
[Form] Deprecate searchAndRenderBlock returning empty string
1 parent 4a7e6fa commit 259ef8b

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

UPGRADE-4.2.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
UPGRADE FROM 4.1 to 4.2
2+
=======================
3+
4+
Form
5+
----
6+
7+
* Deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered.
8+
Instead of expecting such calls return empty string, check if 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+
```

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
{%- if form is rootform -%}
2323
{{ form_errors(form) }}
2424
{%- endif -%}
25-
{{- block('form_rows') -}}
2625
{{- form_rest(form) -}}
2726
</div>
2827
{%- endblock form_widget_compound -%}

src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_widget_compound.html.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
<?php if (!$form->parent && $errors): ?>
33
<?php echo $view['form']->errors($form) ?>
44
<?php endif ?>
5-
<?php echo $view['form']->block($form, 'form_rows') ?>
65
<?php echo $view['form']->rest($form) ?>
76
</div>

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('Calling the "%s()" method for fields which were already rendered is deprecated since Symfony 4.1 and will throw an exception in 5.0.', __METHOD__), 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.'));
135138
return '';
136139
}
137140

0 commit comments

Comments
 (0)