Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f2d19c1

Browse filesBrowse files
committed
derive the view timezone from the model timezone
1 parent aa9ccf8 commit f2d19c1
Copy full SHA for f2d19c1

File tree

2 files changed

+25
-4
lines changed
Filter options

2 files changed

+25
-4
lines changed

‎src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
+16-4Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,18 @@ public function configureOptions(OptionsResolver $resolver)
280280
return null;
281281
};
282282

283+
$viewTimezone = static function (Options $options, $value): ?string {
284+
if (null !== $value) {
285+
return $value;
286+
}
287+
288+
if (null !== $options['model_timezone'] && null === $options['reference_date']) {
289+
return $options['model_timezone'];
290+
}
291+
292+
return null;
293+
};
294+
283295
$resolver->setDefaults([
284296
'hours' => range(0, 23),
285297
'minutes' => range(0, 59),
@@ -290,7 +302,7 @@ public function configureOptions(OptionsResolver $resolver)
290302
'with_minutes' => true,
291303
'with_seconds' => false,
292304
'model_timezone' => $modelTimezone,
293-
'view_timezone' => null,
305+
'view_timezone' => $viewTimezone,
294306
'reference_date' => null,
295307
'placeholder' => $placeholderDefault,
296308
'html5' => true,
@@ -310,12 +322,12 @@ public function configureOptions(OptionsResolver $resolver)
310322
'choice_translation_domain' => false,
311323
]);
312324

313-
$resolver->setNormalizer('model_timezone', function (Options $options, $modelTimezone): ?string {
314-
if (null !== $modelTimezone && $options['view_timezone'] !== $modelTimezone && null === $options['reference_date']) {
325+
$resolver->setNormalizer('view_timezone', function (Options $options, $viewTimezone): ?string {
326+
if (null !== $options['model_timezone'] && $viewTimezone !== $options['model_timezone'] && null === $options['reference_date']) {
315327
throw new LogicException(sprintf('Using different values for the "model_timezone" and "view_timezone" options without configuring a reference date is not supported.'));
316328
}
317329

318-
return $modelTimezone;
330+
return $viewTimezone;
319331
});
320332

321333
$resolver->setNormalizer('placeholder', $placeholderNormalizer);

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,15 @@ public function testModelTimezoneDefaultToReferenceDateTimezoneIfProvided()
859859
$this->assertSame('Europe/Berlin', $form->getConfig()->getOption('model_timezone'));
860860
}
861861

862+
public function testViewTimezoneDefaultsToModelTimezoneIfProvided()
863+
{
864+
$form = $this->factory->create(static::TESTED_TYPE, null, [
865+
'model_timezone' => 'Europe/Berlin',
866+
]);
867+
868+
$this->assertSame('Europe/Berlin', $form->getConfig()->getOption('view_timezone'));
869+
}
870+
862871
public function testPassDefaultChoiceTranslationDomain()
863872
{
864873
$form = $this->factory->create(static::TESTED_TYPE);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.