<?php
declare(strict_types=1);
namespace Juki\Bundle\AppBundle\EventListener;
use Doctrine\Common\Util\Debug;
use Hitso\Bundle\FormBundle\Event\FormEvent;
use Hitso\Bundle\SectionBundle\Entity\Section\ProductListSection;
use Hitso\Bundle\SectionBundle\Form\Section\ProductsListSectionType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotNull;
/**
* Class ProductListSectionSubscriber
*
* @package Juki\Bundle\AppBundle\EventListener
*/
final class ProductListSectionSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'section.form_init' => 'onFormInit',
];
}
public function onFormInit(FormEvent $event)
{
$builder = $event->getBuilder();
if ($builder->getName() === "products_list_section") {
$builder->remove('view');
$builder->add(
'view',
ChoiceType::class,
[
'label' => 'Widok',
'required' => true,
'choices' => [
'Lista' => ProductListSection::LIST_VIEW,
'Box' => ProductListSection::BOX_VIEW,
],
'constraints' => [
new NotBlank(),
new NotNull(),
],
'position' => ['after' => 'products'],
]
);
}
}
}