EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
4.04k stars 1.02k forks source link

"Symfony\Bridge\Doctrine\Form\Type\EntityType": The required option "class" is missing. #5561

Open ArmandArthur opened 1 year ago

ArmandArthur commented 1 year ago

Describe the bug When i click on "Filters" menu, a popup appear. But display the error: " An error has occurred resolving the options of the form "Symfony\Bridge\Doctrine\Form\Type\EntityType": The required option "class" is missing. "

Version easy admin 4.5.0

Do i miss something or it's a bug? I'm with Symfony 6.2.

mousaidy commented 1 year ago

I have the same problem. any update please?

kov-lucas commented 1 year ago

I have this same issue.. any help?

antoinebourlart commented 1 year ago

Will solve your problem


    public static function new(string $propertyName, ?string $label = null)
    {
        return (new self())
            ->setProperty($propertyName)
            ->setLabel($label)
            ->setTemplatePath('admin/field/your_twig.html.twig')
            ->setFormType(EntityType::class)
            ->setFormTypeOptions([
                'class' => YourClass::class,
            ])
            ->addCssClass('field-integer')
        ;
    }
kov-lucas commented 1 year ago

That works, thanks

colonelclick commented 2 months ago

I had the same error message when making a custom filter. My use case was that I wanted to override the apply method with a rather complex query, so I copied the EntityFilter to a new class and changed only the apply method.

I received an error that the class option did not exist when I tried the solution above. After looking at the available options I stumbled upon this fix. I added this line to the new method which had been copied over from the EntityFilter.

->setFormTypeOption('value_type_options', ['class' => YourClass::class])