-
Notifications
You must be signed in to change notification settings - Fork 33
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
SymfonyForm: ChoiceType issue with choices as (static) function call #76
Comments
Thank you for this PR and issue. It makes it real easy to understand and (hopefully) to fix. |
I'm not sure this is always possible to compute result as function can return dynamic strings. Sample: $countries = [];
if ($options['favorites_countries']) {
// add favorites countries first
..
// add remainings countries
..
}
$builder->add('country', CountryType::class, ['choices' => array_flip($countries)]) As it's a parsing error, avoid using a function call can be a reasonable (temporary?) solution: $countries = [];
if ($options['favorites_countries']) {
....
}
$countries = array_flip($countries);
$builder->add('country', CountryType::class, ['choices' => $countries]) |
Same here with static array:
Error message: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As per php-translation/symfony-bundle#143 :
When I use a function or a static function that returns an array for a ChoiceType element, i get a "Form choice is not an array" error.
The extractor should compute the result of the function and use that to extract the translation items.
Uploading a PR containing test case right now.
The text was updated successfully, but these errors were encountered: