symfony easyadmin form field type entity with filter list

旧时模样 提交于 2019-12-13 16:25:15

问题


I use symfony 3.4 and easycorp/easyadmin-bundle 1.17

This is my class "Quotation", the "artisan" field is an "under registration" of the "Person" entity (person.type = 1) :

class Quotation
{
/** others fields... */

/**
 *  1 => 'artisan', 2 => 'customer'
 */
private $type;

/**
 * @ORM\ManyToOne(targetEntity="Person", inversedBy="artisanQuotations", cascade= { "persist" })
 * @ORM\JoinColumn(name="artisan_id", referencedColumnName="id")
 */
private $artisan;

    /** getters and setters ... */

I have a problem with a form field using a custom field type

form:
    fields:
        ...
        - { property: 'artisan', label: '', type: 'AppBundle\Form\Field\ArtisanType' }

I created this form field type to be able to filter the list thanks to the query_builder :

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('artisan', EntityType::class, array(
        'class' => 'AppBundle:Person',
        'label' => false,
        'query_builder' => function(EntityRepository $er) {
            return $er->createQueryBuilder('person')
                ->where('person.type = 1');
        },
        'attr' => array('data-widget' => 'select2'),
        'multiple' => false,
        'expanded'=> false
    ));
}

my form is displayed perfectly well but when i submit this form i have an error :

Expected argument of type "AppBundle\Entity\Person", "array" given

Thank you in advance for your help

来源:https://stackoverflow.com/questions/52199397/symfony-easyadmin-form-field-type-entity-with-filter-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!