-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form][LanguageType] Add whitelist option #35456
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
Conversation
ebd5c70
to
418f5bf
Compare
Another option would be to filter out options that should not be available (see #32657). |
I didn't know these related issues but the idea is the same I guess: we need more control on "forced" choices. |
I'm sure my comment is naïve, but here it is: in my head, all these prepopulated choice types (language, country, locale, etc.) should define an internal If |
I like @javiereguiluz idea. |
Closing this one then, and let's try to implement Javier idea. |
I don't think we need another option in choice subtypes for this, if one wants to define the |
@HeahDude I don't understand how these things work internally, but this is what we want to provide to end users. Do we agree on it? // display all languages (translated into the user language)
$builder->add('language', LanguageType::class);
// display only these languages (translated into the user language)
$builder->add('language', LanguageType::class, [
'choices' => ['es', 'fr', 'en'],
]);
// display all countries (translated into the user language)
$builder->add('country', CountryType::class);
// display only these countries (translated into the user language)
$builder->add('country', CountryType::class, [
'choices' => ['JP', 'US'],
]);
// etc. |
We agree on the need not on the implementation yet. // display only these languages (translated into the user language)
$builder->add('language', LanguageType::class, [
'choice_filter' => fn($choice) => in_array($choice, ['es', 'fr', 'en'], true),
]); But once we have this feature we could indeed use the |
i generally like @javiereguiluz's proposal, but semantically i expect In this case, adding a new back to #32657 :) |
From my experience, it's common to want a language choice input, but only on "available" (prefiltered) languages from the application. For example, I know my application content must only be available in 5 languages, so I want to display only those 5 options when contributing it.
Currently, I think there is no way to use the core
LanguageType
with only some defined choices. That means I have to create a customLanguageType
(whatever the implementation) and that I don't benefit from the core one easily. I can extend it but that requires additional logic /code.I think that adding a
whitelist
option on allIntl
related core form types would make sense. I'm only pushing the language one right now as a demo and to open the discussion. Maybe that actually adding this option to all core form types that have theChoiceType
as their parent and that somehow force the choices would make sense as well.