vendor/sylius/paypal-plugin/src/Form/Type/ChangePaymentMethodType.php line 14

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sylius\PayPalPlugin\Form\Type;
  4. use Sylius\Component\Core\Model\PaymentInterface;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\Form\FormEvent;
  9. use Symfony\Component\Form\FormEvents;
  10. final class ChangePaymentMethodType extends AbstractType
  11. {
  12.     public function buildForm(FormBuilderInterface $builder, array $options): void
  13.     {
  14.         $builder
  15.             ->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event): void {
  16.                 /** @var PaymentInterface[] $payments */
  17.                 $payments $event->getData();
  18.                 $form $event->getForm();
  19.                 foreach ($payments as $key => $payment) {
  20.                     if (!in_array(
  21.                         $payment->getState(),
  22.                         [PaymentInterface::STATE_NEWPaymentInterface::STATE_CARTPaymentInterface::STATE_PROCESSING]
  23.                     )) {
  24.                         $form->remove((string) $key);
  25.                     }
  26.                 }
  27.             })
  28.         ;
  29.     }
  30.     public function getParent(): string
  31.     {
  32.         return CollectionType::class;
  33.     }
  34.     public function getBlockPrefix(): string
  35.     {
  36.         return 'sylius_change_payment_method';
  37.     }
  38. }