Skip to content

Commit 561767c

Browse files
committed
Merge branch '2.8' into 3.3
* 2.8: Fix collision between view properties and form fields
2 parents 73ff764 + c610a32 commit 561767c

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

src/Symfony/Bridge/Twig/Extension/FormExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
1616
use Symfony\Component\DependencyInjection\ContainerInterface;
1717
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
18+
use Symfony\Component\Form\FormView;
1819
use Twig\Environment;
1920
use Twig\Extension\AbstractExtension;
2021
use Twig\Extension\InitRuntimeInterface;
@@ -105,6 +106,7 @@ public function getTests()
105106
{
106107
return array(
107108
new TwigTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'),
109+
new TwigTest('rootform', array($this, 'isRootForm')),
108110
);
109111
}
110112

@@ -164,6 +166,11 @@ public function __unset($name)
164166
unset($this->$name);
165167
}
166168

169+
public function isRootForm(FormView $formView)
170+
{
171+
return null === $formView->parent;
172+
}
173+
167174
/**
168175
* {@inheritdoc}
169176
*/

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

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

277277
{% block form_errors -%}
278278
{% if errors|length > 0 -%}
279-
{% if form.parent %}<span class="help-block">{% else %}<div class="alert alert-danger">{% endif %}
279+
{% if form is not rootform %}<span class="help-block">{% else %}<div class="alert alert-danger">{% endif %}
280280
<ul class="list-unstyled">
281281
{%- for error in errors -%}
282282
<li><span class="glyphicon glyphicon-exclamation-sign"></span> {{ error.message }}</li>
283283
{%- endfor -%}
284284
</ul>
285-
{% if form.parent %}</span>{% else %}</div>{% endif %}
285+
{% if form is not rootform %}</span>{% else %}</div>{% endif %}
286286
{%- endif %}
287287
{%- endblock form_errors %}

src/Symfony/Bridge/Twig/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') -}}
@@ -339,7 +339,7 @@
339339
{% endif %}
340340
{%- endfor %}
341341

342-
{% if not form.methodRendered and form.parent is null %}
342+
{% if not form.methodRendered and form is rootform %}
343343
{%- do form.setMethodRendered() -%}
344344
{% set method = method|upper %}
345345
{%- if method in ["GET", "POST"] -%}

src/Symfony/Bridge/Twig/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) -}}

src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,22 @@ public function testStartTagHasActionAttributeWhenActionIsZero()
146146
$this->assertSame('<form name="form" method="get" action="0">', $html);
147147
}
148148

149+
public function isRootFormProvider()
150+
{
151+
return array(
152+
array(true, new FormView()),
153+
array(false, new FormView(new FormView())),
154+
);
155+
}
156+
157+
/**
158+
* @dataProvider isRootFormProvider
159+
*/
160+
public function testIsRootForm($expected, FormView $formView)
161+
{
162+
$this->assertSame($expected, $this->extension->isRootForm($formView));
163+
}
164+
149165
protected function renderForm(FormView $view, array $vars = array())
150166
{
151167
return (string) $this->renderer->renderBlock($view, 'form', $vars);

0 commit comments

Comments
 (0)