EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

The option "query_builder" does not exist

Open AntoineLemaire opened this issue 3 years ago • 5 comments

Describe the bug After upgrade to v3.1.6, my AssociationField throw an exception. This seems to be caused by https://github.com/EasyCorp/EasyAdminBundle/pull/3551

The error is still present in last release v3.2.7

image

To Reproduce

My Admin Controller:

class RestaurantCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Restaurant::class;
    }

    public function configureActions(Actions $actions): Actions
    {
        return $actions
            ->add(Crud::PAGE_INDEX, Action::DETAIL);
    }

    public function configureFields(string $pageName): iterable
    {
        yield NumberField::new('id', 'id');
        yield TextField::new('name', 'admin.restaurant.name.label');
        yield AssociationField::new('address', 'admin.restaurant.address.label')
            ->setFormType(AddressFormType::class)
            ->renderAsNativeWidget()
        ;
        yield EmailField::new('email', 'admin.restaurant.email.label');
        yield TelephoneField::new('phone', 'admin.restaurant.phone.label')
            ->hideOnIndex();
        yield BooleanField::new('open', 'admin.restaurant.open.label');
    }
}

My Entity Restaurant is really classic:

/**
 * @ORM\Entity
 * @ORM\Table(name="restaurant")
 */
class Restaurant
{
    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var string
     * @ORM\Column(type="string", length=255)
     */
    protected $name;

    /**
     * @var Address
     *
     * @ORM\ManyToOne(targetEntity="Address", cascade={"persist"})
     * @ORM\JoinColumn(name="address_id", referencedColumnName="id")
     */
    protected $address;

And my AddressFormType

class AddressFormType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('street', TextType::class, ['label' => 'admin.restaurant.address.street.label', 'required' => false])
            ->add('additional', TextType::class, ['label' => 'admin.restaurant.address.additional.label', 'required' => false])
            ->add('zipCode', TextType::class, ['label' => 'admin.restaurant.address.zip_code.label', 'required' => false])
            ->add('city', TextType::class, ['label' => 'admin.restaurant.address.city.label', 'required' => true])
            ->add('country', TextType::class, ['label' => 'admin.restaurant.address.country.label', 'required' => false])
        ;
    }

    /**
     * @param OptionsResolver $resolver
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Address::class,
        ]);
    }
}

AntoineLemaire avatar Feb 26 '21 16:02 AntoineLemaire

@AntoineLemaire, a test like this should fix the regression you encounter : https://github.com/Yopai/EasyAdminBundle/commit/fe275f236e797e1802af005d4987d9ed24aac49a

Until a fix is officially made, you can create a fork, cherry-pick this commit, and instruct composer to use your fork instead of the official repository. (Or you can modify the files in your vendor at hand, but it may/will be overriden on the next update)

Yopai avatar Mar 06 '21 10:03 Yopai

I tried the fix above as I was getting the same error. Now its a different error

An error has occurred resolving the options of the form "App\Form\ManageContactPermissionsType": The option "class" does not exist. Defined options are: "action", "allow_extra_fields", "allow_file_upload", "attr", "attr_translation_parameters", "auto_initialize", "block_name", "block_prefix", "by_reference", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "ea_crud_form", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "getter", "help", "help_attr", "help_html", "help_translation_parameters", "inherit_data", "invalid_message", "invalid_message_parameters", "is_empty_callback", "label", "label_attr", "label_format", "label_html", "label_translation_parameters", "legacy_error_messages", "mapped", "method", "post_max_size_message", "property_path", "required", "row_attr", "setter", "translation_domain", "trim", "upload_max_size_message", "validation_groups".

DAmisonSSG avatar May 15 '21 10:05 DAmisonSSG

hi my friend, did you solve this issue @anthony-launay

bocek avatar May 22 '21 15:05 bocek

Do you still experience this bug? Can you please verify if this change fixes it? --> fe275f236e797e1802af005d4987d9ed24aac49a. Thanks!

javiereguiluz avatar Sep 24 '21 18:09 javiereguiluz

Hi @javiereguiluz, as @DAmisonSSG mentionned, it only fix one of the two missing options. "query_builder" gone, but "class" is still there.

image

It works if I add the 'class' option in configureOptions(), same as data_class, but it's weird I need this :thinking: image

Should we replace https://github.com/whatwedo/EasyAdminBundle/blob/master/src/Field/Configurator/AssociationConfigurator.php#L111 and https://github.com/whatwedo/EasyAdminBundle/blob/master/src/Field/Configurator/AssociationConfigurator.php#L128 class by data_class?

AntoineLemaire avatar Sep 26 '21 18:09 AntoineLemaire