-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[WIP][Form] Allow to configure selectable locale and countries #28542
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
[WIP][Form] Allow to configure selectable locale and countries #28542
Conversation
327449e
to
a199522
Compare
What about a more generic |
I think it's already supported in user land: $supportedCountries = ['FR', 'ES', 'CU'];
$builder->add('country', CountryType::class, [
'choice_loader' => new IntlCallbackChoiceLoader(function () use ($supportedCountries) {
return array_intersect(array_flip(Intl::getRegionBundle()->getCountryNames()), $supportedCountries);
}),
]) Although I'm not opposed to adding a shortcut for Intl form types. |
vs. $builder->add('country', CountryType::class, [
'choice_filter' => function ($countryName) use ($supportedCountries) {
return in_array($countryName, $supportedCountries, true);
}),
]) or just saying :) |
Right, cool :) so i'm not the only one. The feature would be priceless, @sstok WDYT? |
That ( |
Yes or pre-defined choice loaders like Intl. The main advantage is you dont have to (re)define a new choice loader basically. Thus knowing about the labels, etc. In your last example it could just as well be a |
Yeah, true :) |
I took a deep dive into the Choice loading system, and almost drowned 🦈 ! The way the choices are loaded does not allow for filtering after their list is created, the loader provides a list and only modifying the loader implementation (which is not always possible) would make it possible to filter the choices before the ChoiseList is created. There is no other option (no pun) but use custom options for each types. But allowing a Closure for a custom filtering (like Edit: I added support for closures. |
Isnt it possible to add a |
@sstok today I can investigate about this |
@yceruto Feel free to do 😄 this thing is driving me crazy. |
See alternative with |
Whoops, a bit late :) yes I agree this can be closed in favor of #28624 |
This fixes #11847, and I added support for countries as well. It should be possible to update the other types also, but languages is more tricky because
en
could mean many different specific locales (this needs some thought if accepted).