<?php
declare(strict_types=1);
namespace App\Form\EventListener\Search\Order;
use App\Entity\Admin\SourceInterface;
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 AddSourceSubscriber extends FormHelper implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SET_DATA => 'preSetData'];
}
public function preSetData(FormEvent $event): void
{
$choices = [];
foreach (SourceInterface::SOURCE_SEARCH_FILTER as $source) {
$choices['app.manager.pages.orders.search.sources.' . $source] = SourceInterface::SOURCE_ALL !== $source ? $source : null;
}
$event->getForm()->add('orderSource', ChoiceType::class, $this->getChoiceParameters(
'app.manager.pages.orders.details.source',
self::PLACEHOLDER_NONE,
false,
[
'choices' => $choices,
'choice_attr' => fn ($choice) => ['data-type' => $choice],
'data' => null,
'expanded' => true,
'multiple' => false,
]
));
}
}