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

[FORM] Add option grouping in TimezoneType #40757

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 4 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update TimezoneType.php
add grouping by continent for (getPhpTimezones and getIntlTimezones) 
to activate grouping, add the "grouping" parameters to true in the options
  • Loading branch information
arvodia authored Apr 10, 2021
commit 734c33a0f22866bab022694ae382e970367c592c
15 changes: 9 additions & 6 deletions 15 src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public function configureOptions(OptionsResolver $resolver)

$choiceTranslationLocale = $options['choice_translation_locale'];

return ChoiceList::loader($this, new IntlCallbackChoiceLoader(function () use ($input, $choiceTranslationLocale) {
return self::getIntlTimezones($input, $choiceTranslationLocale);
return ChoiceList::loader($this, new IntlCallbackChoiceLoader(function () use ($input, $choiceTranslationLocale, $grouping) {
return self::getIntlTimezones($input, $choiceTranslationLocale, $grouping);
}), [$input, $choiceTranslationLocale]);
}

Expand Down Expand Up @@ -122,7 +122,7 @@ private static function getPhpTimezones(string $input, bool $grouping = false):
continue;
}

if ($grouping && $timezone != 'UTC') {
if ($grouping && dirname($timezone) != '.') {
$timezones[str_replace(['/', '_'], [' / ', ' '], dirname($timezone))][str_replace('_', ' ', basename($timezone))] = $timezone;
} else {
$timezones[str_replace(['/', '_'], [' / ', ' '], $timezone)] = $timezone;
Expand All @@ -132,14 +132,17 @@ private static function getPhpTimezones(string $input, bool $grouping = false):
return $timezones;
}

private static function getIntlTimezones(string $input, string $locale = null): array
private static function getIntlTimezones(string $input, string $locale = null, bool $grouping = false): array
{
$timezones = array_flip(Timezones::getNames($locale));

if ('intltimezone' === $input) {
if ('intltimezone' === $input || $grouping) {
foreach ($timezones as $name => $timezone) {
if ('Etc/Unknown' === \IntlTimeZone::createTimeZone($timezone)->getID()) {
if ('intltimezone' === $input && 'Etc/Unknown' === \IntlTimeZone::createTimeZone($timezone)->getID()) {
unset($timezones[$name]);
} elseif ($grouping && dirname($timezone) != '.') {
unset($timezones[$name]);
$timezones[str_replace(['/', '_'], [' / ', ' '], dirname($timezone))][$name] = $timezone;
}
}
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.