Merge branch '4.0'

* 4.0:
  fix merge
  fix merge
  fixed tests
  fixed missing use statement
  fixed deprecated messages in tests
This commit is contained in:
Nicolas Grekas 2018-04-02 16:06:32 +02:00
commit 8659ba9f1f
9 changed files with 56 additions and 72 deletions

View File

@ -32,65 +32,6 @@
{% endif %}
{%- endblock money_widget %}
{% block percent_widget -%}
<div class="input-group">
{{- block('form_widget_simple') -}}
<span class="input-group-addon">%</span>
</div>
{%- endblock percent_widget %}
{% block datetime_widget -%}
{% if widget == 'single_text' %}
{{- block('form_widget_simple') -}}
{% else -%}
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
<div {{ block('widget_container_attributes') }}>
{{- form_errors(form.date) -}}
{{- form_errors(form.time) -}}
{{- form_widget(form.date, { datetime: true } ) -}}
{{- form_widget(form.time, { datetime: true } ) -}}
</div>
{%- endif %}
{%- endblock datetime_widget %}
{% block date_widget -%}
{% if widget == 'single_text' %}
{{- block('form_widget_simple') -}}
{% else -%}
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
{% if datetime is not defined or not datetime -%}
<div {{ block('widget_container_attributes') -}}>
{%- endif %}
{{- date_pattern|replace({
'{{ year }}': form_widget(form.year),
'{{ month }}': form_widget(form.month),
'{{ day }}': form_widget(form.day),
})|raw -}}
{% if datetime is not defined or not datetime -%}
</div>
{%- endif -%}
{% endif %}
{%- endblock date_widget %}
{% block time_widget -%}
{% if widget == 'single_text' %}
{{- block('form_widget_simple') -}}
{% else -%}
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
{% if datetime is not defined or false == datetime -%}
<div {{ block('widget_container_attributes') -}}>
{%- endif -%}
{{- form_widget(form.hour) }}{% if with_minutes %}:{{ form_widget(form.minute) }}{% endif %}{% if with_seconds %}:{{ form_widget(form.second) }}{% endif %}
{% if datetime is not defined or false == datetime -%}
</div>
{%- endif -%}
{% endif %}
{%- endblock time_widget %}
{% block choice_widget_collapsed -%}
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) %}
{%- endblock choice_widget_collapsed %}
{% block checkbox_widget -%}
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
{% if 'checkbox-inline' in parent_label_class %}

View File

@ -9,13 +9,13 @@
<div class="input-group{{ group_class|default('') }}">
{%- if prepend -%}
<div class="input-group-prepend">
<span class="input-group-text">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
<span class="input-group-text">{{ money_pattern|form_encode_currency }}</span>
</div>
{%- endif -%}
{{- block('form_widget_simple') -}}
{%- if append -%}
<div class="input-group-append">
<span class="input-group-text">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
<span class="input-group-text">{{ money_pattern|form_encode_currency }}</span>
</div>
{%- endif -%}
</div>

View File

@ -13,11 +13,11 @@
{% if prepend or append %}
<div class="input-group{{ group_class|default('') }}">
{% if prepend %}
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
<span class="input-group-addon">{{ money_pattern|form_encode_currency }}</span>
{% endif %}
{{- block('form_widget_simple') -}}
{% if append %}
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
<span class="input-group-addon">{{ money_pattern|form_encode_currency }}</span>
{% endif %}
</div>
{% else %}

View File

@ -27,7 +27,7 @@
{% set prepend = '{{' == money_pattern[0:2] %}
{% if not prepend %}
<div class="small-3 large-2 columns">
<span class="prefix">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
<span class="prefix">{{ money_pattern|form_encode_currency }}</span>
</div>
{% endif %}
<div class="small-9 large-10 columns">
@ -35,7 +35,7 @@
</div>
{% if prepend %}
<div class="small-3 large-2 columns">
<span class="postfix">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
<span class="postfix">{{ money_pattern|form_encode_currency }}</span>
</div>
{% endif %}
</div>

View File

@ -82,10 +82,15 @@ class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
__DIR__.'/Fixtures/templates/form',
)), array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addExtension($this->extension);
$environment->addExtension(new FormExtension());
$environment->setCharset('ISO-8859-1');
$this->extension->initRuntime($environment);
$rendererEngine = new TwigRendererEngine(array(
'bootstrap_3_layout.html.twig',
'custom_widgets.html.twig',
), $environment);
$this->renderer = new FormRenderer($rendererEngine, $this->getMockBuilder('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')->getMock());
$this->registerTwigRuntimeLoader($environment, $this->renderer);
$view = $this->factory
->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\MoneyType')

View File

@ -19,6 +19,7 @@ use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Tests\AbstractBootstrap4HorizontalLayoutTest;
use Twig\Environment;
/**
* Class providing test cases for the Bootstrap 4 Twig form theme.
@ -44,7 +45,7 @@ class FormExtensionBootstrap4HorizontalLayoutTest extends AbstractBootstrap4Hori
__DIR__.'/Fixtures/templates/form',
));
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
$environment = new Environment($loader, array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addExtension(new FormExtension());

View File

@ -19,6 +19,7 @@ use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Tests\AbstractBootstrap4LayoutTest;
use Twig\Environment;
/**
* Class providing test cases for the Bootstrap 4 horizontal Twig form theme.
@ -42,7 +43,7 @@ class FormExtensionBootstrap4LayoutTest extends AbstractBootstrap4LayoutTest
__DIR__.'/Fixtures/templates/form',
));
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
$environment = new Environment($loader, array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addExtension(new FormExtension());
@ -78,6 +79,36 @@ class FormExtensionBootstrap4LayoutTest extends AbstractBootstrap4LayoutTest
$this->assertSame('<form name="form" method="get" action="0">', $html);
}
public function testMoneyWidgetInIso()
{
$environment = new Environment(new StubFilesystemLoader(array(
__DIR__.'/../../Resources/views/Form',
__DIR__.'/Fixtures/templates/form',
)), array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addExtension(new FormExtension());
$environment->setCharset('ISO-8859-1');
$rendererEngine = new TwigRendererEngine(array(
'bootstrap_4_layout.html.twig',
'custom_widgets.html.twig',
), $environment);
$this->renderer = new FormRenderer($rendererEngine, $this->getMockBuilder('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')->getMock());
$this->registerTwigRuntimeLoader($environment, $this->renderer);
$view = $this->factory
->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\MoneyType')
->createView()
;
$this->assertSame(<<<'HTML'
<div class="input-group"><div class="input-group-prepend">
<span class="input-group-text">&euro; </span>
</div><input type="text" id="name" name="name" required="required" class="form-control" /></div>
HTML
, trim($this->renderWidget($view)));
}
protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->renderer->renderBlock($view, 'form', $vars);

View File

@ -172,13 +172,18 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
__DIR__.'/Fixtures/templates/form',
)), array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addExtension($this->extension);
$environment->addExtension(new FormExtension());
$environment->setCharset('ISO-8859-1');
$this->extension->initRuntime($environment);
$rendererEngine = new TwigRendererEngine(array(
'form_div_layout.html.twig',
'custom_widgets.html.twig',
), $environment);
$this->renderer = new FormRenderer($rendererEngine, $this->getMockBuilder('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')->getMock());
$this->registerTwigRuntimeLoader($environment, $this->renderer);
$view = $this->factory
->createNamed('name', 'money')
->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\MoneyType')
->createView()
;

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Form;
use Symfony\Component\Form\Exception\LogicException;
use Symfony\Component\Form\Exception\BadMethodCallException;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Twig\Environment;
/**
* Renders a form into HTML using a rendering engine.