Browse Source

#784 : Continue to follow the BC Breaks on the default options induced by the new form component

Baptiste "Talus" Clavie 13 years ago
parent
commit
e03d3e4fbe

+ 5 - 3
Form/Type/ImmutableArrayType.php

@@ -14,6 +14,8 @@ namespace Sonata\AdminBundle\Form\Type;
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\FormBuilderInterface;
 
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+
 use Sonata\AdminBundle\Form\EventListener\ResizeFormListener;
 
 class ImmutableArrayType extends AbstractType
@@ -36,11 +38,11 @@ class ImmutableArrayType extends AbstractType
     /**
      * {@inheritDoc}
      */
-    public function getDefaultOptions()
+    public function setDefaultOptions(OptionsResolverInterface $resolver)
     {
-        return array(
+        $resolver->setDefaults(array(
             'keys'    => array(),
-        );
+        ));
     }
 
     /**

+ 6 - 13
Form/Type/ModelReferenceType.php

@@ -17,7 +17,9 @@ use Symfony\Component\Form\FormFactoryInterface;
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\FormInterface;
 use Symfony\Component\Form\FormView;
+
 use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+use Symfony\Component\OptionsResolver\Options;
 
 use Sonata\AdminBundle\Form\EventListener\MergeCollectionListener;
 use Sonata\AdminBundle\Form\ChoiceList\ModelChoiceList;
@@ -38,25 +40,16 @@ class ModelReferenceType extends AbstractType
     public function setDefaultOptions(OptionsResolverInterface $resolver)
     {
         $compound = function (Options $options) {
-            return $options['parent'];
+            return isset($options['parent']) ? $options['parent'] : 'hidden';
         };
+        
         $resolver->setDefaults(array(
             'compound' => $compound,
+            'model_manager' => null,
+            'class' => null
         ));
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public function getDefaultOptions()
-    {
-        return array(
-            'model_manager'     => null,
-            'class'             => null,
-            'parent'            => 'hidden',
-        );
-    }
-
     /**
      * {@inheritDoc}
      */

+ 6 - 17
Form/Type/ModelType.php

@@ -45,21 +45,11 @@ class ModelType extends AbstractType
 
     public function setDefaultOptions(OptionsResolverInterface $resolver)
     {
-        $compound = function (Options $options) {
-            return isset($options['parent']) ? $options['parent'] : 'choice';
-        };
         $resolver->setDefaults(array(
-            'compound' => $compound,
-        ));
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public function getDefaultOptions()
-    {
-        $options = array(
+            'compound'          => function (Options $options) {
+                return isset($options['parent']) ? $options['parent'] : 'choice';
+            },
+                    
             'template'          => 'choice',
             'multiple'          => false,
             'expanded'          => false,
@@ -70,6 +60,7 @@ class ModelType extends AbstractType
             'choices'           => null,
             'parent'            => 'choice',
             'preferred_choices' => array(),
+            
             'choice_list'       => function (Options $options, $previousValue) {
                 if ($previousValue instanceof ChoiceListInterface
                         && count($choices = $previousValue->getChoices())) {
@@ -84,9 +75,7 @@ class ModelType extends AbstractType
                     $options['choices']
                 );
             }
-        );
-
-        return $options;
+        ));
     }
 
     /**

+ 9 - 6
Form/Type/TranslatableChoiceType.php

@@ -17,7 +17,9 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
 use Symfony\Component\Form\FormInterface;
 use Symfony\Component\Form\FormView;
 use Symfony\Component\Form\FormBuilderInterface;
+
 use Symfony\Component\OptionsResolver\Options;
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
 
 class TranslatableChoiceType extends ChoiceType
 {
@@ -32,33 +34,34 @@ class TranslatableChoiceType extends ChoiceType
     }
 
     /**
-     * @param array $options
-     *
-     * @return array
+     * {@inheritedDoc}
      */
-    public function getDefaultOptions()
+    public function setDefaultOptions(OptionsResolverInterface $resolver)
     {
-        return array(
+        $resolver->setDefaults(array(
             'multiple'          => false,
             'expanded'          => false,
             'choice_list'       => null,
             'choices'           => array(),
             'preferred_choices' => array(),
             'catalogue'         => 'messages',
+            
             'empty_data'        => function (Options $options, $previousValue) {
                 $multiple = isset($options['multiple']) && $options['multiple'];
                 $expanded = isset($options['expanded']) && $options['expanded'];
 
                 return $multiple || $expanded ? array() : '';
             },
+                    
             'empty_value'       => function (Options $options, $previousValue) {
                 $multiple = isset($options['multiple']) && $options['multiple'];
                 $expanded = isset($options['expanded']) && $options['expanded'];
 
                 return $multiple || $expanded || !isset($options['empty_value']) ? null : '';
             },
+                    
             'error_bubbling'    => false,
-        );
+        ));
     }
 
     public function buildForm(FormBuilderInterface $builder, array $options)