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

Skip to content

Commit c214eb1

Browse files
committed
[Form] Deprecate searchAndRenderBlock returning empty string
1 parent c54faf4 commit c214eb1

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

UPGRADE-4.1.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ Form
6363
}
6464
}
6565
```
66+
* Deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered.
67+
Instead of expecting such calls return empty string, check if field has already been rendered.
68+
69+
Before:
70+
```twig
71+
{% for field in fields %}
72+
{{ form_widget(field) }}
73+
{% endfor %}
74+
```
75+
76+
After:
77+
```twig
78+
{% for field in fields %}
79+
{% if not field.rendered %}
80+
{{ form_widget(field) }}
81+
{% endif %}
82+
{% endfor %}
83+
```
6684

6785
FrameworkBundle
6886
---------------

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 -%}

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* deprecated the `ChoiceLoaderInterface` implementation in `CountryType`, `LanguageType`, `LocaleType` and `CurrencyType`
1111
* added `input=datetime_immutable` to DateType, TimeType, DateTimeType
1212
* added `rounding_mode` option to MoneyType
13+
* deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered.
1314

1415
4.0.0
1516
-----

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)