Skip to content

Commit

Permalink
Disable "enabled" field on PayPal payment method
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Sep 10, 2020
1 parent 53ef2aa commit 6743ead
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Form/Extension/PaymentMethodTypeExtension.php
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];
}
}
4 changes: 4 additions & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
</parameters>

<services>
<service id="Sylius\PayPalPlugin\Form\Extension\PaymentMethodTypeExtension">
<tag name="form.type_extension" extended-type="Sylius\Bundle\PaymentBundle\Form\Type\PaymentMethodType" />
</service>

<service id="Sylius\PayPalPlugin\Form\Type\PayPalConfigurationType">
<tag name="sylius.gateway_configuration_type" type="sylius.pay_pal" label="sylius.pay_pal.label" />
</service>
Expand Down

0 comments on commit 6743ead

Please sign in to comment.