feature #35205 [Form] derive the view timezone from the model timezone (xabbuh)
This PR was merged into the 5.1-dev branch.
Discussion
----------
[Form] derive the view timezone from the model timezone
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Tickets | Fix #32805
| License | MIT
| Doc PR |
Commits
-------
ef5835d833
derive the view timezone from the model timezone
This commit is contained in:
commit
c29b2a11d4
@ -4,6 +4,7 @@ CHANGELOG
|
||||
5.1.0
|
||||
-----
|
||||
|
||||
* The `view_timezone` option defaults to the `model_timezone` if no `reference_date` is configured.
|
||||
* Added default `inputmode` attribute to Search, Email and Tel form types.
|
||||
|
||||
5.0.0
|
||||
|
@ -280,6 +280,18 @@ class TimeType extends AbstractType
|
||||
return null;
|
||||
};
|
||||
|
||||
$viewTimezone = static function (Options $options, $value): ?string {
|
||||
if (null !== $value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (null !== $options['model_timezone'] && null === $options['reference_date']) {
|
||||
return $options['model_timezone'];
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
$resolver->setDefaults([
|
||||
'hours' => range(0, 23),
|
||||
'minutes' => range(0, 59),
|
||||
@ -290,7 +302,7 @@ class TimeType extends AbstractType
|
||||
'with_minutes' => true,
|
||||
'with_seconds' => false,
|
||||
'model_timezone' => $modelTimezone,
|
||||
'view_timezone' => null,
|
||||
'view_timezone' => $viewTimezone,
|
||||
'reference_date' => null,
|
||||
'placeholder' => $placeholderDefault,
|
||||
'html5' => true,
|
||||
@ -310,12 +322,12 @@ class TimeType extends AbstractType
|
||||
'choice_translation_domain' => false,
|
||||
]);
|
||||
|
||||
$resolver->setNormalizer('model_timezone', function (Options $options, $modelTimezone): ?string {
|
||||
if (null !== $modelTimezone && $options['view_timezone'] !== $modelTimezone && null === $options['reference_date']) {
|
||||
$resolver->setNormalizer('view_timezone', function (Options $options, $viewTimezone): ?string {
|
||||
if (null !== $options['model_timezone'] && $viewTimezone !== $options['model_timezone'] && null === $options['reference_date']) {
|
||||
throw new LogicException(sprintf('Using different values for the "model_timezone" and "view_timezone" options without configuring a reference date is not supported.'));
|
||||
}
|
||||
|
||||
return $modelTimezone;
|
||||
return $viewTimezone;
|
||||
});
|
||||
|
||||
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
|
||||
|
@ -859,6 +859,15 @@ class TimeTypeTest extends BaseTypeTest
|
||||
$this->assertSame('Europe/Berlin', $form->getConfig()->getOption('model_timezone'));
|
||||
}
|
||||
|
||||
public function testViewTimezoneDefaultsToModelTimezoneIfProvided()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||
'model_timezone' => 'Europe/Berlin',
|
||||
]);
|
||||
|
||||
$this->assertSame('Europe/Berlin', $form->getConfig()->getOption('view_timezone'));
|
||||
}
|
||||
|
||||
public function testPassDefaultChoiceTranslationDomain()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE);
|
||||
|
Reference in New Issue
Block a user