Merge branch '2.7' into 2.8

* 2.7:
  Fix collision between view properties and form fields
This commit is contained in:
Fabien Potencier 2017-12-04 10:08:18 -08:00
commit c610a32b4b
5 changed files with 28 additions and 5 deletions

View File

@ -14,6 +14,7 @@ namespace Symfony\Bridge\Twig\Extension;
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
use Symfony\Component\Form\FormView;
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\Extension\InitRuntimeInterface;
@ -97,6 +98,7 @@ class FormExtension extends AbstractExtension implements InitRuntimeInterface
{
return array(
new TwigTest('selectedchoice', array($this, 'isSelectedChoice')),
new TwigTest('rootform', array($this, 'isRootForm')),
);
}
@ -156,6 +158,11 @@ class FormExtension extends AbstractExtension implements InitRuntimeInterface
return $choice->value === $selectedValue;
}
public function isRootForm(FormView $formView)
{
return null === $formView->parent;
}
/**
* {@inheritdoc}
*/

View File

@ -238,12 +238,12 @@
{% block form_errors -%}
{% if errors|length > 0 -%}
{% if form.parent %}<span class="help-block">{% else %}<div class="alert alert-danger">{% endif %}
{% if form is not rootform %}<span class="help-block">{% else %}<div class="alert alert-danger">{% endif %}
<ul class="list-unstyled">
{%- for error in errors -%}
<li><span class="glyphicon glyphicon-exclamation-sign"></span> {{ error.message }}</li>
{%- endfor -%}
</ul>
{% if form.parent %}</span>{% else %}</div>{% endif %}
{% if form is not rootform %}</span>{% else %}</div>{% endif %}
{%- endif %}
{%- endblock form_errors %}

View File

@ -15,7 +15,7 @@
{%- block form_widget_compound -%}
<div {{ block('widget_container_attributes') }}>
{%- if form.parent is empty -%}
{%- if form is rootform -%}
{{ form_errors(form) }}
{%- endif -%}
{{- block('form_rows') -}}
@ -308,7 +308,7 @@
{% endif %}
{%- endfor %}
{% if not form.methodRendered and form.parent is null %}
{% if not form.methodRendered and form is rootform %}
{%- do form.setMethodRendered() -%}
{% set method = method|upper %}
{%- if method in ["GET", "POST"] -%}

View File

@ -31,7 +31,7 @@
{%- block form_widget_compound -%}
<table {{ block('widget_container_attributes') }}>
{%- if form.parent is empty and errors|length > 0 -%}
{%- if form is rootform and errors|length > 0 -%}
<tr>
<td colspan="2">
{{- form_errors(form) -}}

View File

@ -170,6 +170,22 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
$this->assertSame('<form name="form" method="get" action="0">', $html);
}
public function isRootFormProvider()
{
return array(
array(true, new FormView()),
array(false, new FormView(new FormView())),
);
}
/**
* @dataProvider isRootFormProvider
*/
public function testIsRootForm($expected, FormView $formView)
{
$this->assertSame($expected, $this->extension->isRootForm($formView));
}
protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);