-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Add input_format option to DateType and DateTimeType #29887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -176,7 +176,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) | |||||
$builder->addModelTransformer(new DateTimeImmutableToDateTimeTransformer()); | ||||||
} elseif ('string' === $options['input']) { | ||||||
$builder->addModelTransformer(new ReversedTransformer( | ||||||
new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone']) | ||||||
new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone'], $options['input_format']) | ||||||
)); | ||||||
} elseif ('timestamp' === $options['input']) { | ||||||
$builder->addModelTransformer(new ReversedTransformer( | ||||||
|
@@ -251,6 +251,7 @@ public function configureOptions(OptionsResolver $resolver) | |||||
'empty_data' => function (Options $options) { | ||||||
return $options['compound'] ? [] : ''; | ||||||
}, | ||||||
'input_format' => 'Y-m-d H:i:s', | ||||||
]); | ||||||
|
||||||
// Don't add some defaults in order to preserve the defaults | ||||||
|
@@ -317,6 +318,8 @@ public function configureOptions(OptionsResolver $resolver) | |||||
|
||||||
return ''; | ||||||
}); | ||||||
|
||||||
$resolver->setAllowedTypes('input_format', 'string'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we validate the passed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. symfony/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php Lines 298 to 299 in a6a1be8
As we are going to do with the time_widget option, I wonder if we should throw an exception when the input_format is passed and the value of input is not strictly equal to string' .
|
||||||
} | ||||||
|
||||||
/** | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we set the default here or rely on the transformer default ? IMHO, it's better here so the form type and the transformer are more decoupled.