Skip to content

Add choice_label support to CrudAutocompleteType#7521

Open
Amoifr wants to merge 2 commits intoEasyCorp:5.xfrom
Amoifr:fix_7462
Open

Add choice_label support to CrudAutocompleteType#7521
Amoifr wants to merge 2 commits intoEasyCorp:5.xfrom
Amoifr:fix_7462

Conversation

@Amoifr
Copy link
Copy Markdown

@Amoifr Amoifr commented Mar 25, 2026

Summary

When using EntityFilter with ->autocomplete() and a custom choice_label, the form crashed with:

The option "choice_label" does not exist.

Root cause: CrudAutocompleteType did not define choice_label as a valid option.

Changes:

  • Add choice_label option to CrudAutocompleteType (supports null, string, callable, bool)
  • Update CrudAutocompleteSubscriber to preserve user-defined choice_label instead of overwriting it

Usage example:

public function configureFilters(Filters $filters): Filters
{
    return $filters
        ->add(EntityFilter::new('plan')
            ->autocomplete()
            ->setFormTypeOption('value_type_options', [
                'choice_label' => static function (Plan $plan) {
                    return $plan->name . ' [' . $plan->project->getName() . ']';
                },
            ])
        );
}

Test plan

  • Manual testing with EntityFilter + autocomplete + custom choice_label

Fix #7462

Amoifr added 2 commits March 30, 2026 09:28
When using EntityFilter with autocomplete() and a custom choice_label,
the form crashed because CrudAutocompleteType did not define choice_label
as a valid option.

Changes:
- Add choice_label option to CrudAutocompleteType
- Preserve user-defined choice_label in CrudAutocompleteSubscriber

Fix EasyCorp#7462
Don't pass null choice_label explicitly to EntityType as it behaves
differently than omitting the option in older Symfony versions.
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

Successfully merging this pull request may close these issues.

Filter + EntityFilter + Autocomplete + custom choice_label = 💥

1 participant