Skip to content

Commit 5b147c6

Browse files
Merge branch '3.4' into 4.0
* 3.4: (24 commits) moved Twig runtime to proper class fixed deprecated messages in tests add PHP errors options to XML schema definition [HttpCache] Unlink tmp file on error Added LB translation for #26327 (Errors sign for people that do not see colors) [TwigBridge] Fix rendering of currency by MoneyType Import InvalidArgumentException in PdoAdapter [DI] Do not suggest writing an implementation when multiple exist [Intl] Update ICU data to 61.1 Use 3rd person verb form in command description [Validator] Add Japanese translation Support phpdbg SAPI in Debug::enable() [HttpKernel] DumpDataCollector: do not flush when a dumper is provided [DI] Fix hardcoded cache dir for warmups [Routing] fix tests [Routing] Fixed the importing of files using glob patterns that match multiple resources [Ldap] cast to string when checking empty passwords [Validator] sync validator translation id [WebProfilerBundle] use the router to resolve file links no type errors with invalid submitted data types ...
2 parents 4d1f449 + 5a403e6 commit 5b147c6

File tree

5 files changed

+125
-2
lines changed

5 files changed

+125
-2
lines changed

Extension/FormExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function getFilters()
6363
{
6464
return array(
6565
new TwigFilter('humanize', array('Symfony\Component\Form\FormRenderer', 'humanize')),
66+
new TwigFilter('form_encode_currency', array('Symfony\Component\Form\FormRenderer', 'encodeCurrency'), array('is_safe' => array('html'), 'needs_environment' => true)),
6667
);
6768
}
6869

Resources/views/Form/bootstrap_3_layout.html.twig

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,83 @@
1414
{{- parent() -}}
1515
{%- endblock button_widget %}
1616

17+
{% block money_widget -%}
18+
{% set prepend = not (money_pattern starts with '{{') %}
19+
{% set append = not (money_pattern ends with '}}') %}
20+
{% if prepend or append %}
21+
<div class="input-group">
22+
{% if prepend %}
23+
<span class="input-group-addon">{{ money_pattern|form_encode_currency }}</span>
24+
{% endif %}
25+
{{- block('form_widget_simple') -}}
26+
{% if append %}
27+
<span class="input-group-addon">{{ money_pattern|form_encode_currency }}</span>
28+
{% endif %}
29+
</div>
30+
{% else %}
31+
{{- block('form_widget_simple') -}}
32+
{% endif %}
33+
{%- endblock money_widget %}
34+
35+
{% block percent_widget -%}
36+
<div class="input-group">
37+
{{- block('form_widget_simple') -}}
38+
<span class="input-group-addon">%</span>
39+
</div>
40+
{%- endblock percent_widget %}
41+
42+
{% block datetime_widget -%}
43+
{% if widget == 'single_text' %}
44+
{{- block('form_widget_simple') -}}
45+
{% else -%}
46+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
47+
<div {{ block('widget_container_attributes') }}>
48+
{{- form_errors(form.date) -}}
49+
{{- form_errors(form.time) -}}
50+
{{- form_widget(form.date, { datetime: true } ) -}}
51+
{{- form_widget(form.time, { datetime: true } ) -}}
52+
</div>
53+
{%- endif %}
54+
{%- endblock datetime_widget %}
55+
56+
{% block date_widget -%}
57+
{% if widget == 'single_text' %}
58+
{{- block('form_widget_simple') -}}
59+
{% else -%}
60+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
61+
{% if datetime is not defined or not datetime -%}
62+
<div {{ block('widget_container_attributes') -}}>
63+
{%- endif %}
64+
{{- date_pattern|replace({
65+
'{{ year }}': form_widget(form.year),
66+
'{{ month }}': form_widget(form.month),
67+
'{{ day }}': form_widget(form.day),
68+
})|raw -}}
69+
{% if datetime is not defined or not datetime -%}
70+
</div>
71+
{%- endif -%}
72+
{% endif %}
73+
{%- endblock date_widget %}
74+
75+
{% block time_widget -%}
76+
{% if widget == 'single_text' %}
77+
{{- block('form_widget_simple') -}}
78+
{% else -%}
79+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
80+
{% if datetime is not defined or false == datetime -%}
81+
<div {{ block('widget_container_attributes') -}}>
82+
{%- endif -%}
83+
{{- form_widget(form.hour) }}{% if with_minutes %}:{{ form_widget(form.minute) }}{% endif %}{% if with_seconds %}:{{ form_widget(form.second) }}{% endif %}
84+
{% if datetime is not defined or false == datetime -%}
85+
</div>
86+
{%- endif -%}
87+
{% endif %}
88+
{%- endblock time_widget %}
89+
90+
{% block choice_widget_collapsed -%}
91+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) %}
92+
{%- endblock choice_widget_collapsed %}
93+
1794
{% block checkbox_widget -%}
1895
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
1996
{% if 'checkbox-inline' in parent_label_class %}

Resources/views/Form/form_div_layout.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
{%- endblock integer_widget -%}
178178

179179
{%- block money_widget -%}
180-
{{ money_pattern|replace({ '{{ widget }}': block('form_widget_simple') })|raw }}
180+
{{ money_pattern|form_encode_currency(block('form_widget_simple')) }}
181181
{%- endblock money_widget -%}
182182

183183
{%- block url_widget -%}
@@ -327,7 +327,7 @@
327327
{%- else -%}
328328
{% set form_method = "POST" %}
329329
{%- endif -%}
330-
<form name="{{ name }}" method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
330+
<form{% if name != '' %} name="{{ name }}"{% endif %} method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
331331
{%- if form_method != method -%}
332332
<input type="hidden" name="_method" value="{{ method }}" />
333333
{%- endif -%}

Tests/Extension/FormExtensionBootstrap3LayoutTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,31 @@ public function testStartTagHasActionAttributeWhenActionIsZero()
7575
$this->assertSame('<form name="form" method="get" action="0">', $html);
7676
}
7777

78+
public function testMoneyWidgetInIso()
79+
{
80+
$environment = new Environment(new StubFilesystemLoader(array(
81+
__DIR__.'/../../Resources/views/Form',
82+
__DIR__.'/Fixtures/templates/form',
83+
)), array('strict_variables' => true));
84+
$environment->addExtension(new TranslationExtension(new StubTranslator()));
85+
$environment->addExtension($this->extension);
86+
$environment->setCharset('ISO-8859-1');
87+
88+
$this->extension->initRuntime($environment);
89+
90+
$view = $this->factory
91+
->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\MoneyType')
92+
->createView()
93+
;
94+
95+
$this->assertSame(<<<'HTML'
96+
<div class="input-group">
97+
<span class="input-group-addon">&euro; </span>
98+
<input type="text" id="name" name="name" required="required" class="form-control" /> </div>
99+
HTML
100+
, trim($this->renderWidget($view)));
101+
}
102+
78103
protected function renderForm(FormView $view, array $vars = array())
79104
{
80105
return (string) $this->renderer->renderBlock($view, 'form', $vars);

Tests/Extension/FormExtensionDivLayoutTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,26 @@ public function testIsRootForm($expected, FormView $formView)
165165
$this->assertSame($expected, \Symfony\Bridge\Twig\Extension\twig_is_root_form($formView));
166166
}
167167

168+
public function testMoneyWidgetInIso()
169+
{
170+
$environment = new Environment(new StubFilesystemLoader(array(
171+
__DIR__.'/../../Resources/views/Form',
172+
__DIR__.'/Fixtures/templates/form',
173+
)), array('strict_variables' => true));
174+
$environment->addExtension(new TranslationExtension(new StubTranslator()));
175+
$environment->addExtension($this->extension);
176+
$environment->setCharset('ISO-8859-1');
177+
178+
$this->extension->initRuntime($environment);
179+
180+
$view = $this->factory
181+
->createNamed('name', 'money')
182+
->createView()
183+
;
184+
185+
$this->assertSame('&euro; <input type="text" id="name" name="name" required="required" />', $this->renderWidget($view));
186+
}
187+
168188
protected function renderForm(FormView $view, array $vars = array())
169189
{
170190
return (string) $this->renderer->renderBlock($view, 'form', $vars);

0 commit comments

Comments
 (0)