From 043adbf116fe55044c8f294a081a5b25c38ad3c0 Mon Sep 17 00:00:00 2001 From: Leny BERNARD Date: Fri, 4 Mar 2016 12:19:53 +0100 Subject: [PATCH] :arrow_up: Symfony ~2.8|~3.0 compatibility --- Controller/PaymentController.php | 3 ++- Form/CardType.php | 34 ++++++++++++-------------------- Resources/config/services.yml | 2 +- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Controller/PaymentController.php b/Controller/PaymentController.php index 99250b9..1388f73 100644 --- a/Controller/PaymentController.php +++ b/Controller/PaymentController.php @@ -6,6 +6,7 @@ use AppVentus\MangopayBundle\Entity\Order; use AppVentus\MangopayBundle\Event\OrderEvent; use AppVentus\MangopayBundle\Event\PreAuthorisationEvent; +use AppVentus\MangopayBundle\Form\CardType; use AppVentus\MangopayBundle\OrderEvents; use MangoPay\CardRegistration; use MangoPay\PayIn; @@ -36,7 +37,7 @@ public function newAction(Request $request, $order) throw $this->createNotFoundException('Order not found'); } //create card form - $form = $this->createForm('appventus_mangopaybundle_card_type'); + $form = $this->createForm(CardType::class); $form->handleRequest($request); if ($form->isValid()) { diff --git a/Form/CardType.php b/Form/CardType.php index 097e11f..88f60f9 100644 --- a/Form/CardType.php +++ b/Form/CardType.php @@ -3,6 +3,9 @@ namespace AppVentus\MangopayBundle\Form; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\Extension\Core\Type\IntegerType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Constraints\NotBlank; @@ -16,7 +19,7 @@ class CardType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('cardNumber', 'text', array( + ->add('cardNumber', TextType::class, array( 'constraints' => array(new NotBlank(['groups' => ['card']])), 'label' => 'appventus_mangopay.card_number.label', 'attr' => array( @@ -25,7 +28,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ), 'mapped' => false )) - ->add('cardHolder', 'text', array( + ->add('cardHolder', TextType::class, array( 'constraints' => array(new NotBlank(['groups' => ['card']])), 'label' => 'appventus_mangopay.card_holder.label', 'attr' => array( @@ -34,7 +37,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ), 'mapped' => false )) - ->add('ccv', 'integer', array( + ->add('ccv', IntegerType::class, array( 'constraints' => array(new NotBlank(['groups' => ['card']])), 'label' => 'appventus_mangopay.card_ccv.label', 'attr' => array( @@ -43,23 +46,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) ), 'mapped' => false )) - ->add('cardExpiryMonth', 'choice', array( + ->add('cardExpiryMonth', ChoiceType::class, array( 'constraints' => array(new NotBlank(['groups' => ['card']])), 'label' => 'appventus_mangopay.card_expiry_month.label', - 'choices' => array( - "01" => "01", - "02" => "02", - "03" => "03", - "04" => "04", - "05" => "05", - "06" => "06", - "07" => "07", - "08" => "08", - "09" => "09", - "10" => "10", - "11" => "11", - "12" => "12", - ), + 'choices' => ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"], + 'choices_as_values' => true, 'attr' => array( 'data-id' => 'appventus_mangopay_card_expiry_month', 'placeholder' => 'appventus_mangopay.card_expiry_month.placeholder', @@ -75,9 +66,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) $year = (int) $year + 1; } - $builder->add('cardExpiryYear', 'choice', array( - 'constraints' => array(new NotBlank(['groups' => ['card']])), + $builder->add('cardExpiryYear', ChoiceType::class, array( + 'constraints' => array(new NotBlank(['groups' => ['card']])), 'choices' => $years, + 'choices_as_values' => true, 'attr' => array( 'data-id' => 'appventus_mangopay_card_expiry_year', 'placeholder' => 'appventus_mangopay.card_expiry_year.placeholder', @@ -92,7 +84,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * @return string */ - public function getName() + public function getBlockPrefix() { return 'appventus_mangopaybundle_card_type'; } diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 30af1c5..1f6e5b8 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -55,4 +55,4 @@ services: appventus_mangopay.form.card: class: %appventus_mangopay.form.card% tags: - - { name: form.type, alias: appventus_mangopaybundle_card_type } + - { name: form.type }