Merge branch '2.8' into 3.3
* 2.8: Fix collision between view properties and form fields
This commit is contained in:
commit
561767ce65
@ -15,6 +15,7 @@ use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
|
|||||||
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
|
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
use Symfony\Component\Form\ChoiceList\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;
|
||||||
@ -105,6 +106,7 @@ class FormExtension extends AbstractExtension implements InitRuntimeInterface
|
|||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new TwigTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'),
|
new TwigTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'),
|
||||||
|
new TwigTest('rootform', array($this, 'isRootForm')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,6 +166,11 @@ class FormExtension extends AbstractExtension implements InitRuntimeInterface
|
|||||||
unset($this->$name);
|
unset($this->$name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRootForm(FormView $formView)
|
||||||
|
{
|
||||||
|
return null === $formView->parent;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -276,12 +276,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') -}}
|
||||||
@ -339,7 +339,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) -}}
|
||||||
|
@ -146,6 +146,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->renderer->renderBlock($view, 'form', $vars);
|
return (string) $this->renderer->renderBlock($view, 'form', $vars);
|
||||||
|
Reference in New Issue
Block a user