You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.5KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Field\Filter;
  3. use Doctrine\ORM\EntityRepository;
  4. use Doctrine\ORM\QueryBuilder;
  5. use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
  6. use Lc\SovBundle\Field\Filter\AssociationFilter;
  7. use Lc\SovBundle\Field\Filter\FilterTrait;
  8. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  9. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. /**
  12. * @author La clic ! <contact@laclic.fr>
  13. */
  14. class ProductCategoriesFilter extends AssociationFilter
  15. {
  16. public function buildProperty(FormBuilderInterface $builder, FieldDto $fieldDto, $options = array())
  17. {
  18. $targetEntity = $options['entity_dto']->getPropertyMetadata($fieldDto->getProperty())->get('targetEntity');
  19. $builder->add(
  20. $fieldDto->getProperty(),
  21. EntityType::class,
  22. array(
  23. 'class' => $targetEntity,
  24. 'placeholder' => '--',
  25. 'choices' => $fieldDto->getFormTypeOption('choices'),
  26. 'required' => false,
  27. 'attr' => array(
  28. 'class' => 'select2 input-sm',
  29. 'form' => 'filters-form',
  30. ),
  31. )
  32. );
  33. }
  34. public function applyFilter(RepositoryQueryInterface $repositoryQuery, string $fieldProperty, $filteredValue = null)
  35. {
  36. if ($filteredValue !== null) {
  37. $repositoryQuery->filterByProductCategory($filteredValue);
  38. }
  39. }
  40. }