Skip to content

Commit 401f543

Browse files
ro0NLfabpot
authored andcommitted
[TwigBridge] Fix rendering of currency by MoneyType
1 parent 70d970a commit 401f543

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php echo str_replace('{{ widget }}', $view['form']->block($form, 'form_widget_simple'), $money_pattern) ?>
1+
<?php echo $view['form']->formEncodeCurrency($money_pattern, $view['form']->block($form, 'form_widget_simple')) ?>

Templating/Helper/FormHelper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,20 @@ public function humanize($text)
260260
{
261261
return $this->renderer->humanize($text);
262262
}
263+
264+
/**
265+
* @internal
266+
*/
267+
public function formEncodeCurrency($text, $widget = '')
268+
{
269+
if ('UTF-8' === $charset = $this->getCharset()) {
270+
$text = htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
271+
} else {
272+
$text = htmlentities($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
273+
$text = iconv('UTF-8', $charset, $text);
274+
$widget = iconv('UTF-8', $charset, $widget);
275+
}
276+
277+
return str_replace('{{ widget }}', $widget, $text);
278+
}
263279
}

Tests/Templating/Helper/FormHelperDivLayoutTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ protected function tearDown()
6161
parent::tearDown();
6262
}
6363

64+
public function testMoneyWidgetInIso()
65+
{
66+
$this->engine->setCharset('ISO-8859-1');
67+
68+
$view = $this->factory
69+
->createNamed('name', 'money')
70+
->createView()
71+
;
72+
73+
$this->assertSame('&euro; <input type="text" id="name" name="name" required="required" />', $this->renderWidget($view));
74+
}
75+
6476
protected function renderForm(FormView $view, array $vars = array())
6577
{
6678
return (string) $this->engine->get('form')->form($view, $vars);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"symfony/security-core": "~2.6.13|~2.7.9|~2.8",
3131
"symfony/security-csrf": "~2.6",
3232
"symfony/stopwatch": "~2.3",
33-
"symfony/templating": "~2.1",
33+
"symfony/templating": "~2.7",
3434
"symfony/translation": "~2.7",
3535
"doctrine/annotations": "~1.0"
3636
},

0 commit comments

Comments
 (0)