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

Allow the time type to use the preferred_choices for hours,minutes and s... #10012

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions 22 src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
// Only pass a subset of the options to children
$hourOptions['choices'] = $hours;
$hourOptions['empty_value'] = $options['empty_value']['hour'];
$hourOptions['preferred_choices'] = $options['preferred_choices']['hours'];

if ($options['with_minutes']) {
foreach ($options['minutes'] as $minute) {
Expand All @@ -72,6 +73,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)

$minuteOptions['choices'] = $minutes;
$minuteOptions['empty_value'] = $options['empty_value']['minute'];
$minuteOptions['preferred_choices'] = $options['preferred_choices']['minutes'];
}

if ($options['with_seconds']) {
Expand All @@ -83,6 +85,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)

$secondOptions['choices'] = $seconds;
$secondOptions['empty_value'] = $options['empty_value']['second'];
$secondOptions['preferred_choices'] = $options['preferred_choices']['seconds'];
}

// Append generic carry-along options
Expand Down Expand Up @@ -173,12 +176,30 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
);
};

$preferredChoicesNormalizer = function (Options $options, $preferredChoices) {
if (is_array($preferredChoices)) {
$default = array();

return array_merge(
array('hours' => $default, 'minutes' => $default, 'seconds' => $default),
$preferredChoices
);
}

return array(
'hours' => $default,
'minutes' => $default,
'seconds' => $default
);
};

$resolver->setDefaults(array(
'hours' => range(0, 23),
'minutes' => range(0, 59),
'seconds' => range(0, 59),
'widget' => 'choice',
'input' => 'datetime',
'preferred_choices'=> array(),
'with_minutes' => true,
'with_seconds' => false,
'model_timezone' => null,
Expand All @@ -198,6 +219,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)

$resolver->setNormalizers(array(
'empty_value' => $emptyValueNormalizer,
'preferred_choices' => $preferredChoicesNormalizer,
));

$resolver->setAllowedValues(array(
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.