10000 [Form] group_by does not works with callable string · Issue #15542 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] group_by does not works with callable string #15542

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
satanasdiabolo opened this issue Aug 13, 2015 · 3 comments
Closed

[Form] group_by does not works with callable string #15542

satanasdiabolo opened this issue Aug 13, 2015 · 3 comments

Comments

@satanasdiabolo
Copy link

I tried to use 'group_by' option with a call to a static method.

$form = $this->createFormBuilder()
            ->add('files', 'choice', [
                'choices' => [/* Some Choices */],
                'choices_as_values' => true,
                'group_by' => 'MyStatic::method'
            ])
            ->getForm();

Here is a dummy code sample of what I'm doing.
I saw in Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator::createView line 203, the test is if (is_string($groupBy)).
I think it should be if (is_string($groupBy) && !is_callable($groupBy)).

I have test with option choice_value, and other new options, but this bug may exists for those ones too.

@Tobion
Copy link
Contributor
Tobion commented Aug 14, 2015

This would make it impossible to use a property path that has the same name as als a global function. Nvm, one can simply pass a PropertyPath instance as well. So I agree, your suggested change makes sense.

But for your concrete use-case, the static method, you can simply use the array notation of it.

@Tobion
Copy link
Contributor
Tobion commented Aug 15, 2015

See #15561 for a fix.

@satanasdiabolo
Copy link
Author

Thanks a lot, for your help.

@fabpot fabpot closed this as completed Aug 22, 2015
fabpot added a commit that referenced this issue Aug 22, 2015
This PR was merged into the 2.7 branch.

Discussion
----------

[Form] only use PropertyPath if not already callable

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | could be in edge cases
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #15542
| License       | MIT
| Doc PR        | -

Currently it uses a PropertyPath even when the string is already a callable. But the callable string should have higher priority since that is also the one documented in ChoiceListFactoryInterface.

Commits
-------

470b140 [Form] only use PropertyPath if not already callable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0