Skip to content

choice_value and choice_label problem #21587

Closed
@petforsberg

Description

@petforsberg
Q A
Bug report? # yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.2

Seems like a common issue: http://stackoverflow.com/questions/38055465/symfony3-missing-argument-2-for-commonbundle-controller-closure

Here's the doc: http://symfony.com/blog/new-in-symfony-2-7-choice-form-type-refactorization#dynamic-generation-of-choice-names-and-values

and the code from it:

'choice_value' => function ($allChoices, $currentChoiceKey) {
    ...
},

I noticed the same issue with choice_value when working with the Doctrine's ArrayCollection - this code works:

'choice_value' => function($value)
    {
        ...
    }

while this one will bring the error like a given one ("Warning: Missing argument 2 for CommonBundle\Controller\DefaultController::CommonBundle\Controller{closure}()")

'choice_value' => function($value, $key)
    {
        ...
    }

Notice extra $key var. What I get by $value is ArrayCollection - i.e. all the values (choices) available. But I want to have a key, so that I could access only a single value from the whole collection. Do I need to do a work-around hooks by making some $i(terator) global and increment it in the closure?

The same applies to choice_label.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions