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] Remove default option grouping in TimezoneType #31293

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

Merged
merged 1 commit into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -2551,12 +2551,8 @@ public function testTimezone()
[@name="name"]
[@class="my&class form-control"]
[not(@required)]
[./optgroup
[@label="Europe"]
[./option[@value="Europe/Vienna"][@selected="selected"][.="Vienna"]]
]
[count(./optgroup)>10]
[count(.//option)>200]
[./option[@value="Europe/Vienna"][@selected="selected"][.="Europe / Vienna"]]
[count(./option)>200]
'
);
}
Expand All @@ -2572,8 +2568,7 @@ public function testTimezoneWithPlaceholder()
'/select
[@class="my&class form-control"]
[./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Select&Timezone[/trans]"]]
[count(./optgroup)>10]
[count(.//option)>201]
[count(./option)>201]
'
);
}
Expand Down
1 change: 1 addition & 0 deletions 1 src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ CHANGELOG
* dispatch `PreSetDataEvent` on `form.pre_set_data`
* dispatch `PostSetDataEvent` on `form.post_set_data`
* added an `input` option to `NumberType`
* removed default option grouping in `TimezoneType`, use `group_by` instead

4.2.0
-----
Expand Down
17 changes: 2 additions & 15 deletions 17 src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,9 @@ private static function getTimezones(int $regions, string $input): array
continue;
}

$parts = explode('/', $timezone);

if (\count($parts) > 2) {
$region = $parts[0];
$name = $parts[1].' - '.$parts[2];
} elseif (\count($parts) > 1) {
$region = $parts[0];
$name = $parts[1];
} else {
$region = 'Other';
$name = $parts[0];
}

$timezones[$region][str_replace('_', ' ', $name)] = $timezone;
$timezones[str_replace(['/', '_'], [' / ', ' '], $timezone)] = $timezone;
}

return 1 === \count($timezones) ? reset($timezones) : $timezones;
return $timezones;
}
}
11 changes: 3 additions & 8 deletions 11 src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2278,12 +2278,8 @@ public function testTimezone()
'/select
[@name="name"]
[not(@required)]
[./optgroup
[@label="Europe"]
[./option[@value="Europe/Vienna"][@selected="selected"][.="Vienna"]]
]
[count(./optgroup)>10]
[count(.//option)>200]
[./option[@value="Europe/Vienna"][@selected="selected"][.="Europe / Vienna"]]
[count(./option)>200]
'
);
}
Expand All @@ -2298,8 +2294,7 @@ public function testTimezoneWithPlaceholder()
$this->assertWidgetMatchesXpath($form->createView(), [],
'/select
[./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Select&Timezone[/trans]"]]
[count(./optgroup)>10]
[count(.//option)>201]
[count(./option)>201]
'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ public function testTimezonesAreSelectable()
$choices = $this->factory->create(static::TESTED_TYPE)
->createView()->vars['choices'];

$this->assertArrayHasKey('Africa', $choices);
$this->assertContains(new ChoiceView('Africa/Kinshasa', 'Africa/Kinshasa', 'Kinshasa'), $choices['Africa'], '', false, false);

$this->assertArrayHasKey('America', $choices);
$this->assertContains(new ChoiceView('America/New_York', 'America/New_York', 'New York'), $choices['America'], '', false, false);
$this->assertContains(new ChoiceView('Africa/Kinshasa', 'Africa/Kinshasa', 'Africa / Kinshasa'), $choices, '', false, false);
$this->assertContains(new ChoiceView('America/New_York', 'America/New_York', 'America / New York'), $choices, '', false, false);
}

public function testSubmitNull($expected = null, $norm = null, $view = null)
Expand Down Expand Up @@ -83,7 +80,7 @@ public function testFilterByRegions()
$choices = $this->factory->create(static::TESTED_TYPE, null, ['regions' => \DateTimeZone::EUROPE])
->createView()->vars['choices'];

$this->assertContains(new ChoiceView('Europe/Amsterdam', 'Europe/Amsterdam', 'Amsterdam'), $choices, '', false, false);
$this->assertContains(new ChoiceView('Europe/Amsterdam', 'Europe/Amsterdam', 'Europe / Amsterdam'), $choices, '', false, false);
}

/**
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.