<?php
declare(strict_types=1);
namespace App\Form\EventListener\Admin\PaymentMethod\GatewayConfig;
use App\Form\FormHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class AddIsGlobalFieldSubscriber extends FormHelper implements EventSubscriberInterface
{
public function __construct(
private bool $checked = false
) {
}
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SET_DATA => 'preSetData'];
}
public function preSetData(FormEvent $event): void
{
$attr = [];
if (true === $this->checked) {
$attr['checked'] = 'checked';
}
$event->getForm()->add('is_global', CheckboxType::class, $this->getCheckParameters(
'app.admin.pages.payment_methods.form.is_global',
self::PLACEHOLDER_ENABLE_ASK,
null,
compact('attr'),
));
}
}