Cephalopodius
Cephalopodius

Reputation: 125

easyaDmin 3.3 create custom filter

I struggle to understand how i'm supposed to do a custom filter in easyadmin 3.3 . The documentation isnt helping. I alway got an error Error: Class App\Entity\entity1 has no field or association named "field1"

So i tried to put the mapping as false to prevent this, following the doc and i'm getting this

Attempted to call an undefined method named "mapped" of class "App\Controller\Admin\Filter\customfilter".

here my code : Crud controller :

  public function configureFilters(Filters $filters): Filters
        {
          return $filters
           
            ->add(getAutoclaveFilter::new('fiedWithNoAssociation')->mapped(false))
            ;
        }

custom filter :

class GetAutoclaveFilter implements FilterInterface
{
    use FilterTrait;

    public static function new(string $propertyName, $label = null): self
    {
        return (new self())
            ->setFilterFqcn(__CLASS__)
            ->setProperty($propertyName)
            ->setLabel($label);

    }

    public function apply(QueryBuilder $queryBuilder, FilterDataDto $filterDataDto, ?FieldDto $fieldDto, EntityDto $entityDto): void
    {
            $queryBuilder->andWhere(sprintf('%s.%s = :value', $filterDataDto->getEntityAlias(), $filterDataDto->getProperty()))
                ->setParameter('value',$filterDataDto );
       
    }

And the entity :

  public function fiedWithNoAssociation()
    {
      return $this->getEntityAssociated()->getEntity2();
    }

What i'm doing wrong ? Is the mapped function not implemented yet ?

Upvotes: 1

Views: 3031

Answers (1)

Лёлик
Лёлик

Reputation: 21

Use instead of mapped:

->setFormTypeOption('mapped', false)

Upvotes: 2

Related Questions