vendor/bitbag/elasticsearch-plugin/src/Form/Type/ProductOptionsFilterType.php line 21

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file has been created by developers from BitBag.
  4.  * Feel free to contact us once you face any issues or want to start
  5.  * another great project.
  6.  * You can find more information about us on https://bitbag.io and write us
  7.  * an email on hello@bitbag.io.
  8.  */
  9. declare(strict_types=1);
  10. namespace BitBag\SyliusElasticsearchPlugin\Form\Type;
  11. use BitBag\SyliusElasticsearchPlugin\Context\ProductOptionsContextInterface;
  12. use BitBag\SyliusElasticsearchPlugin\Form\Type\ChoiceMapper\ProductOptionsMapperInterface;
  13. use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
  14. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  15. use Symfony\Component\Form\FormBuilderInterface;
  16. final class ProductOptionsFilterType extends AbstractFilterType
  17. {
  18.     private ProductOptionsContextInterface $productOptionsContext;
  19.     private ConcatedNameResolverInterface $optionNameResolver;
  20.     private ProductOptionsMapperInterface $productOptionsMapper;
  21.     public function __construct(
  22.         ProductOptionsContextInterface $productOptionsContext,
  23.         ConcatedNameResolverInterface $optionNameResolver,
  24.         ProductOptionsMapperInterface $productOptionsMapper
  25.     ) {
  26.         $this->productOptionsContext $productOptionsContext;
  27.         $this->optionNameResolver $optionNameResolver;
  28.         $this->productOptionsMapper $productOptionsMapper;
  29.     }
  30.     public function buildForm(FormBuilderInterface $builder, array $options): void
  31.     {
  32.         foreach ($this->productOptionsContext->getOptions() as $productOption) {
  33.             $name $this->optionNameResolver->resolvePropertyName($productOption->getCode());
  34.             $choices $this->productOptionsMapper->mapToChoices($productOption);
  35.             $choices array_unique($choices);
  36.             $builder->add($nameChoiceType::class, [
  37.                 'label' => $productOption->getName(),
  38.                 'required' => false,
  39.                 'multiple' => true,
  40.                 'expanded' => true,
  41.                 'choices' => $choices,
  42.             ]);
  43.         }
  44.     }
  45. }