Skip to content

Commit 7cd8b53

Browse files
Merge branch '3.4' into 4.0
* 3.4: [DI] Fix missing unset leading to false-positive circular ref [DI] Fix deep-inlining of non-shared refs parse newlines in quoted multiline strings Fix collision between view properties and form fields Fix collision between view properties and form fields [SecurityBundle] Fix compat with HttpFoundation >=3.4 Fix collision between view properties and form fields
2 parents aacf6c5 + d0842da commit 7cd8b53

File tree

7 files changed

+32
-8
lines changed

7 files changed

+32
-8
lines changed

Extension/FormExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
1515
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
16+
use Symfony\Component\Form\FormView;
1617
use Twig\Extension\AbstractExtension;
1718
use Twig\TwigFilter;
1819
use Twig\TwigFunction;
@@ -72,9 +73,15 @@ public function getTests()
7273
{
7374
return array(
7475
new TwigTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'),
76+
new TwigTest('rootform', array($this, 'isRootForm')),
7577
);
7678
}
7779

80+
public function isRootForm(FormView $formView)
81+
{
82+
return null === $formView->parent;
83+
}
84+
7885
/**
7986
* {@inheritdoc}
8087
*/

Resources/views/Form/bootstrap_3_layout.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@
140140

141141
{% block form_errors -%}
142142
{% if errors|length > 0 -%}
143-
{% if form.parent %}<span class="help-block">{% else %}<div class="alert alert-danger">{% endif %}
143+
{% if form is not rootform %}<span class="help-block">{% else %}<div class="alert alert-danger">{% endif %}
144144
<ul class="list-unstyled">
145145
{%- for error in errors -%}
146146
<li><span class="glyphicon glyphicon-exclamation-sign"></span> {{ error.message }}</li>
147147
{%- endfor -%}
148148
</ul>
149-
{% if form.parent %}</span>{% else %}</div>{% endif %}
149+
{% if form is not rootform %}</span>{% else %}</div>{% endif %}
150150
{%- endif %}
151151
{%- endblock form_errors %}

Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173

174174
{% block form_errors -%}
175175
{%- if errors|length > 0 -%}
176-
<div class="{% if form.parent %}invalid-feedback{% else %}alert alert-danger{% endif %}">
176+
<div class="{% if form is not rootform %}invalid-feedback{% else %}alert alert-danger{% endif %}">
177177
<ul class="list-unstyled mb-0">
178178
{%- for error in errors -%}
179179
<li>{{ error.message }}</li>

Resources/views/Form/form_div_layout.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
{%- block form_widget_compound -%}
1717
<div {{ block('widget_container_attributes') }}>
18-
{%- if form.parent is empty -%}
18+
{%- if form is rootform -%}
1919
{{ form_errors(form) }}
2020
{%- endif -%}
2121
{{- block('form_rows') -}}
@@ -349,7 +349,7 @@
349349
{% endif %}
350350
{%- endfor %}
351351

352-
{% if not form.methodRendered and form.parent is null %}
352+
{% if not form.methodRendered and form is rootform %}
353353
{%- do form.setMethodRendered() -%}
354354
{% set method = method|upper %}
355355
{%- if method in ["GET", "POST"] -%}

Resources/views/Form/form_table_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
{%- block form_widget_compound -%}
3333
<table {{ block('widget_container_attributes') }}>
34-
{%- if form.parent is empty and errors|length > 0 -%}
34+
{%- if form is rootform and errors|length > 0 -%}
3535
<tr>
3636
<td colspan="2">
3737
{{- form_errors(form) -}}

Resources/views/Form/foundation_5_layout.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,11 @@
318318

319319
{% block form_errors -%}
320320
{% if errors|length > 0 -%}
321-
{% if form.parent %}<small class="error">{% else %}<div data-alert class="alert-box alert">{% endif %}
321+
{% if form is not rootform %}<small class="error">{% else %}<div data-alert class="alert-box alert">{% endif %}
322322
{%- for error in errors -%}
323323
{{ error.message }}
324324
{% if not loop.last %}, {% endif %}
325325
{%- endfor -%}
326-
{% if form.parent %}</small>{% else %}</div>{% endif %}
326+
{% if form is not rootform %}</small>{% else %}</div>{% endif %}
327327
{%- endif %}
328328
{%- endblock form_errors %}

Tests/Extension/FormExtensionDivLayoutTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,23 @@ public function testStartTagHasActionAttributeWhenActionIsZero()
149149
$this->assertSame('<form name="form" method="get" action="0">', $html);
150150
}
151151

152+
public function isRootFormProvider()
153+
{
154+
return array(
155+
array(true, new FormView()),
156+
array(false, new FormView(new FormView())),
157+
);
158+
}
159+
160+
/**
161+
* @dataProvider isRootFormProvider
162+
*/
163+
public function testIsRootForm($expected, FormView $formView)
164+
{
165+
$extension = new FormExtension();
166+
$this->assertSame($expected, $extension->isRootForm($formView));
167+
}
168+
152169
protected function renderForm(FormView $view, array $vars = array())
153170
{
154171
return (string) $this->renderer->renderBlock($view, 'form', $vars);

0 commit comments

Comments
 (0)