-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c539cef
commit 4c500c9
Showing
4 changed files
with
3 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,17 +16,14 @@ | |
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Form\FormView; | ||
use Symfony\Component\OptionsResolver\Options; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Contracts\Translation\LocaleAwareInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
/** | ||
* Class BasePickerType (to factorize DatePickerType and DateTimePickerType code. | ||
* | ||
* @author Hugo Briand <[email protected]> | ||
*/ | ||
abstract class BasePickerType extends AbstractType implements LocaleAwareInterface | ||
abstract class BasePickerType extends AbstractType | ||
{ | ||
/** | ||
* @var array<string, array<string>|string> | ||
|
@@ -68,43 +65,8 @@ abstract class BasePickerType extends AbstractType implements LocaleAwareInterfa | |
'monthSelectorType' => 'string', | ||
]; | ||
|
||
public function __construct( | ||
protected TranslatorInterface $translator, | ||
protected string $locale | ||
) { | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setNormalizer( | ||
'format', | ||
function (Options $options, int|string $format) { | ||
if (isset($options['date_format']) && \is_string($options['date_format'])) { | ||
return $options['date_format']; | ||
} | ||
|
||
if (\is_int($format)) { | ||
$timeFormat = \IntlDateFormatter::NONE; | ||
// if (true === $options['dp_pick_time']) { | ||
// $timeFormat = true === $options['dp_use_seconds'] ? | ||
// DateTimeType::DEFAULT_TIME_FORMAT : | ||
// \IntlDateFormatter::SHORT; | ||
// } | ||
$intlDateFormatter = new \IntlDateFormatter( | ||
$this->locale, | ||
$format, | ||
$timeFormat, | ||
null, | ||
\IntlDateFormatter::GREGORIAN | ||
); | ||
|
||
return $intlDateFormatter->getPattern(); | ||
} | ||
|
||
return $format; | ||
} | ||
); | ||
|
||
$resolver->setDefault('datepicker_options', function (OptionsResolver $datePickerResolver) { | ||
$dateTimeNormalizer = static function (OptionsResolver $options, string|array|\DateTimeInterface $value): string|array { | ||
if ($value instanceof \DateTimeInterface) { | ||
|
@@ -142,33 +104,10 @@ function (Options $options, int|string $format) { | |
|
||
public function finishView(FormView $view, FormInterface $form, array $options): void | ||
{ | ||
$format = $options['format']; | ||
|
||
// use seconds if it's allowed in format | ||
// $options['dp_use_seconds'] = str_contains($format, 's'); | ||
|
||
// if ($options['dp_min_date'] instanceof \DateTimeInterface) { | ||
// $options['dp_min_date'] = $this->formatObject($options['dp_min_date'], $format); | ||
// } | ||
// if ($options['dp_max_date'] instanceof \DateTimeInterface) { | ||
// $options['dp_max_date'] = $this->formatObject($options['dp_max_date'], $format); | ||
// } | ||
|
||
$view->vars['type'] = 'text'; | ||
$view->vars['datepicker_use_button'] = $options['datepicker_use_button'] ?? false; | ||
$view->vars['datepicker_options'] = $options['datepicker_options']; | ||
} | ||
|
||
public function getLocale(): string | ||
{ | ||
return $this->locale; | ||
} | ||
|
||
public function setLocale(string $locale): void | ||
{ | ||
$this->locale = $locale; | ||
} | ||
|
||
/** | ||
* Gets base default options for the form types | ||
* (except `datepicker_options` which should be handled with `getCommonDatepickerDefaults()`). | ||
|
@@ -180,6 +119,7 @@ protected function getCommonDefaults(): array | |
return [ | ||
'widget' => 'single_text', | ||
'datepicker_use_button' => true, | ||
'html5' => false, | ||
]; | ||
} | ||
|
||
|
@@ -227,17 +167,4 @@ protected function getCommonDatepickerDefaults(): array | |
// 'monthSelectorType' => 'dropdown', | ||
]; | ||
} | ||
|
||
// private function formatObject(\DateTimeInterface $dateTime, string $format): string | ||
// { | ||
// $formatter = new \IntlDateFormatter($this->locale, \IntlDateFormatter::NONE, \IntlDateFormatter::NONE); | ||
// $formatter->setPattern($format); | ||
|
||
// $formatted = $formatter->format($dateTime); | ||
// if (!\is_string($formatted)) { | ||
// throw new \RuntimeException(sprintf('The format "%s" is invalid.', $format)); | ||
// } | ||
|
||
// return $formatted; | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters