|
@@ -14,6 +14,8 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
|
|
use Symfony\Component\Form\AbstractType;
|
|
|
use Symfony\Component\Form\FormInterface;
|
|
|
use Symfony\Component\Form\FormBuilder;
|
|
|
+use Symfony\Component\Form\Exception\CreationException;
|
|
|
+use Symfony\Component\Form\Exception\FormException;
|
|
|
use Symfony\Component\Form\Extension\Core\ChoiceList\PaddedChoiceList;
|
|
|
use Symfony\Component\Form\Extension\Core\ChoiceList\MonthChoiceList;
|
|
|
use Symfony\Component\Form\FormView;
|
|
@@ -29,26 +31,26 @@ class DateType extends AbstractType
|
|
|
{
|
|
|
$format = $options['format'];
|
|
|
$pattern = null;
|
|
|
-
|
|
|
+
|
|
|
$allowedFormatOptionValues = array(
|
|
|
\IntlDateFormatter::FULL,
|
|
|
\IntlDateFormatter::LONG,
|
|
|
\IntlDateFormatter::MEDIUM,
|
|
|
\IntlDateFormatter::SHORT,
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
// If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string
|
|
|
if (!in_array($format, $allowedFormatOptionValues, true)) {
|
|
|
if (is_string($format)) {
|
|
|
$defaultOptions = $this->getDefaultOptions($options);
|
|
|
-
|
|
|
+
|
|
|
$format = $defaultOptions['format'];
|
|
|
$pattern = $options['format'];
|
|
|
} else {
|
|
|
- throw new FormException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
|
|
|
+ throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$formatter = new \IntlDateFormatter(
|
|
|
\Locale::getDefault(),
|
|
|
$format,
|