From fc8fb4e26ac2f1898a6691db4f3b16fc077e2512 Mon Sep 17 00:00:00 2001 From: Ramiro Anacona Meneses Date: Thu, 23 Feb 2017 11:40:01 -0500 Subject: [PATCH] add compatibility with symfony 2.8 and 3.0 for choice type field --- Form/Type/ScalingSettingFormType.php | 9 ++++++++- Util/LegacyFormHelper.php | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 Util/LegacyFormHelper.php diff --git a/Form/Type/ScalingSettingFormType.php b/Form/Type/ScalingSettingFormType.php index 8737142..9cc4014 100644 --- a/Form/Type/ScalingSettingFormType.php +++ b/Form/Type/ScalingSettingFormType.php @@ -2,6 +2,7 @@ namespace Anacona16\Bundle\ImageCropBundle\Form\Type; +use Anacona16\Bundle\ImageCropBundle\Util\LegacyFormHelper; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; @@ -25,10 +26,16 @@ public function configureOptions(OptionsResolver $resolver) */ public function buildForm(FormBuilderInterface $builder, array $options) { + $optionsScaling = $options['scaling']; + + if (!LegacyFormHelper::isLegacy()) { + $optionsScaling = array_flip($optionsScaling); + } + $builder ->add('scaling', ChoiceType::class, array( 'label' => 'form.label.scaling', - 'choices' => $options['scaling'], + 'choices' => $optionsScaling, 'translation_domain' => 'ImageCropBundle', )) ; diff --git a/Util/LegacyFormHelper.php b/Util/LegacyFormHelper.php new file mode 100644 index 0000000..ae253ec --- /dev/null +++ b/Util/LegacyFormHelper.php @@ -0,0 +1,24 @@ +