Skip to content

Commit 76cd7e1

Browse files
committed
[Form] Fixed: remove quoted strings from Intl date formats (e.g. es_ES full pattern)
1 parent 9e9f9b5 commit 76cd7e1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Extension/Core/Type/DateType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ public function finishView(FormView $view, FormInterface $form, array $options)
145145

146146
// remove special characters unless the format was explicitly specified
147147
if (!is_string($options['format'])) {
148+
// remove quoted strings first
149+
$pattern = preg_replace('/\'[^\']+\'/', '', $pattern);
150+
151+
// remove remaining special chars
148152
$pattern = preg_replace('/[^yMd]+/', '', $pattern);
149153
}
150154

Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,20 @@ public function testDontPassDatePatternIfText()
614614
$this->assertFalse(isset($view->vars['date_pattern']));
615615
}
616616

617+
public function testDatePatternFormatWithQuotedStrings()
618+
{
619+
\Locale::setDefault('es_ES');
620+
621+
$form = $this->factory->create('date', null, array(
622+
// EEEE, d 'de' MMMM 'de' y
623+
'format' => \IntlDateFormatter::FULL,
624+
));
625+
626+
$view = $form->createView();
627+
628+
$this->assertEquals('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
629+
}
630+
617631
public function testPassWidgetToView()
618632
{
619633
$form = $this->factory->create('date', null, array(

0 commit comments

Comments
 (0)