EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

[symfony 7.3] Public constructor required in custom filter

Open BaptisteChabrol opened this issue 6 months ago • 4 comments

Describe the bug When creating a custom filter, I have the error :

Invalid service "App\Foo": its constructor must be public. Did you miss configuring a factory or a static constructor? Try using the "#[Autoconfigure(constructor: ...)]" attribute for the latter.

To Reproduce Create a custom filter using the FilterTrait like in the documentation.

(OPTIONAL) Additional context It's maybe due to the symfony 7.3 version since this PR

Changing FilterTrait private constructor to public resolve the issue for me.

BaptisteChabrol avatar Jun 06 '25 08:06 BaptisteChabrol

You can exclude the filter from autoconfiguring for a temporary workaround.

fracsi avatar Jun 07 '25 07:06 fracsi

Ok but as you say it's for a temporary workaround. Is there something missing from my filter to avoid this error?

BaptisteChabrol avatar Jun 09 '25 13:06 BaptisteChabrol

Hi, same issue.

Do we need to make a correction on easyadmin or on the app ?

MrJuliuss avatar Jun 12 '25 12:06 MrJuliuss

Hi, same issue.

Do we need to make a correction on easyadmin or on the app ?

Like I said I change the easycorp/easyadmin-bundle/src/Filter/FilterTrait.php constructor to public and it's work if you want a temporary correction. For a long-term correction I don't know

BaptisteChabrol avatar Jun 13 '25 10:06 BaptisteChabrol

@BaptisteChabrol can it be, that you have your custom filter in the Controller/Admin namespace? I had the same error and when "solving" it with a custom FilterTrait and a public constructor .. just another problem popped up.

I think, the solution is actually, to move your custom filter (and fields) outside of the Controller namespace.. e.g. to Form\Admin than those are by design not part of the AutoConfiguration anymore. That solved it for me and seems logical, since a Field is not a Controller anyway.

There was somewhere else a bug report around DependencyInjection, which pointed me in that direction.

slaubi avatar Sep 10 '25 08:09 slaubi