Merge branch '2.7' into 2.8
* 2.7: Fix collision between view properties and form fields
This commit is contained in:
commit
c610a32b4b
@ -14,6 +14,7 @@ namespace Symfony\Bridge\Twig\Extension;
|
|||||||
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
|
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
|
||||||
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
|
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
|
||||||
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
|
use Symfony\Component\Form\FormView;
|
||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
use Twig\Extension\AbstractExtension;
|
use Twig\Extension\AbstractExtension;
|
||||||
use Twig\Extension\InitRuntimeInterface;
|
use Twig\Extension\InitRuntimeInterface;
|
||||||
@ -97,6 +98,7 @@ class FormExtension extends AbstractExtension implements InitRuntimeInterface
|
|||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new TwigTest('selectedchoice', array($this, 'isSelectedChoice')),
|
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;
|
return $choice->value === $selectedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRootForm(FormView $formView)
|
||||||
|
{
|
||||||
|
return null === $formView->parent;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -238,12 +238,12 @@
|
|||||||
|
|
||||||
{% block form_errors -%}
|
{% block form_errors -%}
|
||||||
{% if errors|length > 0 -%}
|
{% 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">
|
<ul class="list-unstyled">
|
||||||
{%- for error in errors -%}
|
{%- for error in errors -%}
|
||||||
<li><span class="glyphicon glyphicon-exclamation-sign"></span> {{ error.message }}</li>
|
<li><span class="glyphicon glyphicon-exclamation-sign"></span> {{ error.message }}</li>
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
</ul>
|
</ul>
|
||||||
{% if form.parent %}</span>{% else %}</div>{% endif %}
|
{% if form is not rootform %}</span>{% else %}</div>{% endif %}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endblock form_errors %}
|
{%- endblock form_errors %}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
{%- block form_widget_compound -%}
|
{%- block form_widget_compound -%}
|
||||||
<div {{ block('widget_container_attributes') }}>
|
<div {{ block('widget_container_attributes') }}>
|
||||||
{%- if form.parent is empty -%}
|
{%- if form is rootform -%}
|
||||||
{{ form_errors(form) }}
|
{{ form_errors(form) }}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{{- block('form_rows') -}}
|
{{- block('form_rows') -}}
|
||||||
@ -308,7 +308,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
{% if not form.methodRendered and form.parent is null %}
|
{% if not form.methodRendered and form is rootform %}
|
||||||
{%- do form.setMethodRendered() -%}
|
{%- do form.setMethodRendered() -%}
|
||||||
{% set method = method|upper %}
|
{% set method = method|upper %}
|
||||||
{%- if method in ["GET", "POST"] -%}
|
{%- if method in ["GET", "POST"] -%}
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
{%- block form_widget_compound -%}
|
{%- block form_widget_compound -%}
|
||||||
<table {{ block('widget_container_attributes') }}>
|
<table {{ block('widget_container_attributes') }}>
|
||||||
{%- if form.parent is empty and errors|length > 0 -%}
|
{%- if form is rootform and errors|length > 0 -%}
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
{{- form_errors(form) -}}
|
{{- form_errors(form) -}}
|
||||||
|
@ -170,6 +170,22 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
|
|||||||
$this->assertSame('<form name="form" method="get" action="0">', $html);
|
$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())
|
protected function renderForm(FormView $view, array $vars = array())
|
||||||
{
|
{
|
||||||
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);
|
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);
|
||||||
|
Reference in New Issue
Block a user