<?php
declare(strict_types=1);
namespace App\Form\EventListener\Search\Franchise;
use App\Entity\Franchise\FranchiseInterface;
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 AddStatusSubscriber extends FormHelper implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SET_DATA => 'preSetData'];
}
public function preSetData(FormEvent $event): void
{
$choices = ['app.global.filter.status.choices.all' => null];
foreach (FranchiseInterface::STATUS as $status) {
$choices['app.global.filter.status.choices.' . $status] = $status;
}
$event->getForm()->add('status', ChoiceType::class, $this->getChoiceParameters(
'app.global.filter.status.label',
self::PLACEHOLDER_NONE,
false,
[
'choices' => $choices,
'data' => null,
]
));
}
}