8000 feature #27247 [Form] Deprecate `searchAndRenderBlock` returning empt… · symfony/symfony@86361e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 86361e5

Browse files
committed
feature #27247 [Form] Deprecate searchAndRenderBlock returning empty string (ostrolucky)
This PR was squashed before being merged into the 4.2-dev branch (closes #27247). Discussion ---------- [Form] Deprecate `searchAndRenderBlock` returning empty string | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #26531 | License | MIT | Doc PR | - I would like to remove this silent behavior, because it's confusing Commits ------- 02f2f0e [Form] Deprecate `searchAndRenderBlock` returning empty string
2 parents c871857 + 02f2f0e commit 86361e5

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

UPGRADE-4.2.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@ Cache
66

77
* Deprecated `CacheItem::getPreviousTags()`, use `CacheItem::getMetadata()` instead.
88

9+
Form
10+
----
11+
12+
* Deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered.
13+
Instead of expecting such calls to return empty strings, check if the field has already been rendered.
14+
15+
Before:
16+
```twig
17+
{% for field in fieldsWithPotentialDuplicates %}
18+
{{ form_widget(field) }}
19+
{% endfor %}
20+
```
21+
22+
After:
23+
```twig
24+
{% for field in fieldsWithPotentialDuplicates if not field.rendered %}
25+
{{ form_widget(field) }}
26+
{% endfor %}
27+
```
928
Security
1029
--------
1130

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 (!$child->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