Skip to content

[Form] ChoiceType preferred_choices does not work with grouped choices #2869

Closed
@ericclemmons

Description

@ericclemmons

Because the buildView function does the following, any nested choices are incorrectly intersected by their group rather than the true choices:

        $choices = $form->getAttribute('choice_list')->getChoices();
        $preferred = array_flip($form->getAttribute('preferred_choices'));

        $view
            ...
            ->set('preferred_choices', array_intersect_key($choices, $preferred))
            ->set('choices', array_diff_key($choices, $preferred))

How would you prefer this to be resolved?

A couple of new helper functions like:

ChoiceType#getPreferredChoices($choices, $preferred) and ChoiceType#getRemainingChoices($choices, $preferred)

Or modify ChoiceList to support these convenience methods:

ChoiceList#getPreferredChoices($preferred) and ChoiceList#getRemainingChoices($preferred)

Suggestions welcome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions