-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable "enabled" field on PayPal payment method
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\PayPalPlugin\Form\Extension; | ||
|
||
use Sylius\Bundle\PaymentBundle\Form\Type\PaymentMethodType; | ||
use Sylius\Component\Core\Model\PaymentMethodInterface; | ||
use Symfony\Component\Form\AbstractTypeExtension; | ||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\FormEvent; | ||
use Symfony\Component\Form\FormEvents; | ||
|
||
final class PaymentMethodTypeExtension extends AbstractTypeExtension | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event): void { | ||
/** @var PaymentMethodInterface $data */ | ||
$data = $event->getData(); | ||
$form = $event->getForm(); | ||
|
||
if ($data->getGatewayConfig()->getFactoryName() === 'sylius.pay_pal') { | ||
$form->add('enabled', CheckboxType::class, [ | ||
'required' => false, | ||
'disabled' => true, | ||
'label' => 'sylius.form.payment_method.enabled', | ||
]); | ||
} | ||
}); | ||
} | ||
|
||
public function getExtendedTypes(): iterable | ||
{ | ||
return [PaymentMethodType::class]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters