src/Juki/Bundle/AppBundle/EventListener/ProductListSectionSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Juki\Bundle\AppBundle\EventListener;
  4. use Doctrine\Common\Util\Debug;
  5. use Hitso\Bundle\FormBundle\Event\FormEvent;
  6. use Hitso\Bundle\SectionBundle\Entity\Section\ProductListSection;
  7. use Hitso\Bundle\SectionBundle\Form\Section\ProductsListSectionType;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. use Symfony\Component\Validator\Constraints\NotBlank;
  11. use Symfony\Component\Validator\Constraints\NotNull;
  12. /**
  13.  * Class ProductListSectionSubscriber
  14.  *
  15.  * @package Juki\Bundle\AppBundle\EventListener
  16.  */
  17. final class ProductListSectionSubscriber implements EventSubscriberInterface
  18. {
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return [
  22.             'section.form_init' => 'onFormInit',
  23.         ];
  24.     }
  25.     public function onFormInit(FormEvent $event)
  26.     {
  27.         $builder $event->getBuilder();
  28.         if ($builder->getName() === "products_list_section") {
  29.             $builder->remove('view');
  30.             $builder->add(
  31.                 'view',
  32.                 ChoiceType::class,
  33.                 [
  34.                     'label'       => 'Widok',
  35.                     'required'    => true,
  36.                     'choices'     => [
  37.                         'Lista' => ProductListSection::LIST_VIEW,
  38.                         'Box'   => ProductListSection::BOX_VIEW,
  39.                     ],
  40.                     'constraints' => [
  41.                         new NotBlank(),
  42.                         new NotNull(),
  43.                     ],
  44.                     'position'    => ['after' => 'products'],
  45.                 ]
  46.             );
  47.         }
  48.     }
  49. }