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