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

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.shop and write us
  7.  * an email on mikolaj.krol@bitbag.pl.
  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.     /** @var ProductOptionsContextInterface */
  19.     private $productOptionsContext;
  20.     /** @var ConcatedNameResolverInterface */
  21.     private $optionNameResolver;
  22.     /** @var ProductOptionsMapperInterface */
  23.     private $productOptionsMapper;
  24.     public function __construct(
  25.         ProductOptionsContextInterface $productOptionsContext,
  26.         ConcatedNameResolverInterface $optionNameResolver,
  27.         ProductOptionsMapperInterface $productOptionsMapper
  28.     ) {
  29.         $this->productOptionsContext $productOptionsContext;
  30.         $this->optionNameResolver $optionNameResolver;
  31.         $this->productOptionsMapper $productOptionsMapper;
  32.     }
  33.     public function buildForm(FormBuilderInterface $builder, array $options): void
  34.     {
  35.         foreach ($this->productOptionsContext->getOptions() as $productOption) {
  36.             $name $this->optionNameResolver->resolvePropertyName($productOption->getCode());
  37.             $choices $this->productOptionsMapper->mapToChoices($productOption);
  38.             $choices array_unique($choices);
  39.             $builder->add($nameChoiceType::class, [
  40.                 'label' => $productOption->getName(),
  41.                 'required' => false,
  42.                 'multiple' => true,
  43.                 'expanded' => true,
  44.                 'choices' => $choices,
  45.             ]);
  46.         }
  47.     }
  48. }