<?php
declare(strict_types=1);
namespace App\Form\EventListener\Search\Order;
use App\Entity\Order\OrderInterface;
use App\Form\FormHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class AddTimeSubscriber extends FormHelper implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SET_DATA => 'preSetData'];
}
public function preSetData(FormEvent $event): void
{
$choices = [];
foreach (OrderInterface::FILTERS as $type) {
$choices['app.order.type.' . $type] = OrderInterface::TYPE_ALL !== $type ? $type : null;
}
$event->getForm()->add('type', ChoiceType::class, $this->getChoiceParameters(
null,
self::PLACEHOLDER_NONE,
false,
[
'choices' => $choices,
'choice_attr' => function ($choice) {
return ['data-type' => $choice];
},
'data' => OrderInterface::TYPE_TODAY,
'expanded' => true,
'multiple' => false,
]
));
}
}