8000 Fix collision between view properties and form fields · symfony/symfony@8505894 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8505894

Browse files
committed
Fix collision between view properties and form fields
1 parent e2c608a commit 8505894

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
@@ -14,6 +14,7 @@
1414
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
1515
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
1616
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
17+
use Symfony\Component\Form\FormView;
1718
use Twig\Environment;
1819
use Twig\Extension\AbstractExtension;
1920
use Twig\Extension\InitRuntimeInterface;
@@ -97,6 +98,7 @@ public function getTests()
9798
{
9899
return array(
99100
new TwigTest('selectedchoice', array($this, 'isSelectedChoice')),
101+
new TwigTest('rootform', array($this, 'isRootForm')),
100102
);
101103
}
102104

@@ -156,6 +158,11 @@ public function isSelectedChoice(ChoiceView $choice, $selectedValue)
156158
return $choice->value === $selectedValue;
157159
}
158160

161+
public function isRootForm(FormView $formView)
162+
{
163+
return null === $formView->parent;
164+
}
165+
159166
/**
160167
* {@inheritdoc}
161168
*/

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
@@ -238,12 +238,12 @@
238238

239239
{% block form_errors -%}
240240
{% if errors|length > 0 -%}
241-
{% if form.parent %}<span class="help-block">{% else %}<div class="alert alert-danger">{% endif %}
241+
{% if form is not rootform %}<span class="help-block">{% else %}<div class="alert alert-danger">{% endif %}
242242
<ul class="list-unstyled">
243243
{%- for error in errors -%}
244244
<li><span class="glyphicon glyphicon-exclamation-sign"></span> {{ error.message }}</li>
245245
{%- endfor -%}
246246
</ul>
247-
{% if form.parent %}</span>{% else %}</div>{% endif %}
247+
{% if form is not rootform %}</span>{% else %}</div>{% endif %}
248248
{%- endif %}
249249
{%- 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') -}}
@@ -303,7 +303,7 @@
303303
{% endif %}
304304
{%- endfor %}
305305

306-
{% if not form.methodRendered and form.parent is null %}
306+
{% if not form.methodRendered and form is rootform %}
307307
{%- do form.setMethodRendered() -%}
308308
{% set method = method|upper %}
309309
{%- 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 testIsChoiceSelected($expected, $choice, $value)
146146
$this->assertSame($expected, $this->extension->isSelectedChoice($choice, $value));
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->extension->renderer->renderBlock($view, 'form', $vars);

0 commit comments

Comments
 (0)
0