<?php
declare(strict_types=1);
namespace App\Form\EventListener\Global;
use App\Entity\Shop\ShopInterface;
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 AddOrderIntervalSubscriber extends FormHelper implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SET_DATA => 'preSetData'];
}
public function preSetData(FormEvent $event): void
{
$choices = [];
foreach (ShopInterface::ORDERING_INTERVALS as $interval) {
$choices[$interval] = $interval;
}
$event->getForm()->add(
'orderInterval',
ChoiceType::class,
$this->getChoiceParameters('app.global.labels.order_interval', self::PLACEHOLDER_CHOICE, true, compact('choices'))
);
}
}