src/Form/EventListener/Admin/PaymentMethod/GatewayConfig/AddIsGlobalFieldSubscriber.php line 25

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventListener\Admin\PaymentMethod\GatewayConfig;
  4. use App\Form\FormHelper;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  7. use Symfony\Component\Form\FormEvent;
  8. use Symfony\Component\Form\FormEvents;
  9. class AddIsGlobalFieldSubscriber extends FormHelper implements EventSubscriberInterface
  10. {
  11.     public function __construct(
  12.         private bool $checked false
  13.     ) {
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [FormEvents::PRE_SET_DATA => 'preSetData'];
  18.     }
  19.     public function preSetData(FormEvent $event): void
  20.     {
  21.         $attr = [];
  22.         if (true === $this->checked) {
  23.             $attr['checked'] = 'checked';
  24.         }
  25.         $event->getForm()->add('is_global'CheckboxType::class, $this->getCheckParameters(
  26.             'app.admin.pages.payment_methods.form.is_global',
  27.             self::PLACEHOLDER_ENABLE_ASK,
  28.             null,
  29.             compact('attr'),
  30.         ));
  31.     }
  32. }