Skip to content

Commit c7bb2a9

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: [ErrorHandler] Return false directly and remove unused variable [OptionsResolver] Assert that the error type is valid in deprecations test [HttpClient] Allow bearer token with colon [Form] Fix custom formats deprecation with HTML5 widgets [Translator] Optional Intl dependency [Contracts][Translation] Optional Intl dependency [ErrorHandler] Escape JSON encoded log context update missing translations arabic [Yaml] simplify the test fix test by letting mock throw the actual expected exception
2 parents 275e107 + 1988f54 commit c7bb2a9

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

Extension/Core/Type/DateTimeType.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Symfony\Component\Form\FormView;
2727
use Symfony\Component\Form\ReversedTransformer;
2828
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
29+
use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;
2930
use Symfony\Component\OptionsResolver\Options;
3031
use Symfony\Component\OptionsResolver\OptionsResolver;
3132

@@ -338,13 +339,22 @@ public function configureOptions(OptionsResolver $resolver)
338339

339340
return $timeWidget;
340341
});
341-
$resolver->setNormalizer('html5', function (Options $options, $html5) {
342-
if ($html5 && self::HTML5_FORMAT !== $options['format']) {
343-
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is enabled.', self::class));
344-
}
345-
346-
return $html5;
347-
});
342+
foreach (['html5', 'format'] as $option) {
343+
$resolver->setDeprecated($option, static function (Options $options, $value) use ($option): string {
344+
try {
345+
$html5 = 'html5' === $option ? $value : $options['html5'];
346+
$format = 'format' === $option ? $value : $options['format'];
347+
} catch (OptionDefinitionException $e) {
348+
return '';
349+
}
350+
351+
if ($html5 && self::HTML5_FORMAT !== $format) {
352+
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is disabled.', self::class));
353+
}
354+
355+
return $html5;
356+
});
357+
}
348358
}
349359

350360
/**

Extension/Core/Type/DateType.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Symfony\Component\Form\FormView;
2424
use Symfony\Component\Form\ReversedTransformer;
2525
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
26+
use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;
2627
use Symfony\Component\OptionsResolver\Options;
2728
use Symfony\Component\OptionsResolver\OptionsResolver;
2829

@@ -323,13 +324,23 @@ public function configureOptions(OptionsResolver $resolver)
323324
$resolver->setAllowedTypes('days', 'array');
324325
$resolver->setAllowedTypes('input_format', 'string');
325326

326-
$resolver->setNormalizer('html5', function (Options $options, $html5) {
327-
if ($html5 && 'single_text' === $options['widget'] && self::HTML5_FORMAT !== $options['format']) {
328-
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is enabled.', self::class));
329-
}
327+
foreach (['html5', 'widget', 'format'] as $option) {
328+
$resolver->setDeprecated($option, static function (Options $options, $value) use ($option): string {
329+
try {
330+
$html5 = 'html5' === $option ? $value : $options['html5'];
331+
$widget = 'widget' === $option ? $value : $options['widget'];
332+
$format = 'format' === $option ? $value : $options['format'];
333+
} catch (OptionDefinitionException $e) {
334+
return '';
335+
}
330336

331-
return $html5;
332-
});
337+
if ($html5 && 'single_text' === $widget && self::HTML5_FORMAT !== $format) {
338+
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is disabled.', self::class));
339+
}
340+
341+
return $html5;
342+
});
343+
}
333344
}
334345

335346
/**

Tests/Extension/Core/Type/DateTimeTypeTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ public function testSingleTextWidgetWithCustomNonHtml5Format()
520520
'widget' => 'single_text',
521521
'date_format' => \IntlDateFormatter::SHORT,
522522
'format' => null,
523+
'html5' => false,
523524
]);
524525
$view = $form->createView();
525526

0 commit comments

Comments
 (0)