phpsymfonyeasyadmin

Easyadmin entity filter "Is one of" in many-to-one relationship


When I have a many-to-many relationship Easyadmin adds this as a filter with two inputs. In the first I can select equals/not equals and in the second I can enter multiple values.

When I have a many-to-one relatioship Easyadmin also adds this as a filter with two inputs. The first is the same (equals/not equals) but in the second I can select only one value.

Is there a way to tell Easyadmin that I want to select multiple items in the one-to-many relationship?

Example:

My users have a property "state". One-to-many. And now I want to filter for users that live in either state a, state b, or state c.


Solution

  • I'm guessing you want to use an EntityFilter to filter on your OneToMany relation.

    EntityFilter use a symfony EntityType so you can use the form option multiple set to true.

    To modify a form option with easyadmin you can use the setFormTypeOption method, and to modify an option on your EntityType you can use value_type_options.

    So just use it like this:

    return $filters
                //...
                ->add(EntityFilter::new('state', 'State')
                    ->setFormTypeOption('value_type_options.multiple', true));