Browse Source

#784 : Fix the BC Break in the form default options

Baptiste "Talus" Clavie 13 years ago
parent
commit
5669653c45
3 changed files with 22 additions and 23 deletions
  1. 6 8
      Form/Type/AdminType.php
  2. 11 12
      Form/Type/BooleanType.php
  3. 5 3
      Form/Type/CollectionType.php

+ 6 - 8
Form/Type/AdminType.php

@@ -15,6 +15,8 @@ use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\FormTypeInterface;
 use Symfony\Component\Form\FormBuilderInterface;
 
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+
 use Sonata\AdminBundle\Form\DataTransformer\ArrayToModelTransformer;
 
 class AdminType extends AbstractType
@@ -25,6 +27,7 @@ class AdminType extends AbstractType
     public function buildForm(FormBuilderInterface $builder, array $options)
     {
         $admin = $this->getAdmin($options);
+        
         if ($options['delete'] && $admin->isGranted('DELETE') ) {
             $builder->add('_delete', 'checkbox', array('required' => false, 'property_path' => false));
         }
@@ -37,15 +40,10 @@ class AdminType extends AbstractType
 
         $builder->prependClientTransformer(new ArrayToModelTransformer($admin->getModelManager(), $admin->getClass()));
     }
-
-    /**
-     * {@inheritDoc}
-     */
-    public function getDefaultOptions()
+    
+    public function setDefaultOptions(OptionsResolverInterface $resolver)
     {
-        return array(
-            'delete' => true,
-        );
+        $resolver->setDefaults(array('delete' => true));
     }
 
     /**

+ 11 - 12
Form/Type/BooleanType.php

@@ -14,6 +14,8 @@ namespace Sonata\AdminBundle\Form\Type;
 use Symfony\Component\Form\Extension\Core\Type\ChoiceType as FormChoiceType;
 use Symfony\Component\Translation\TranslatorInterface;
 
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+
 class BooleanType extends FormChoiceType
 {
     const TYPE_YES = 1;
@@ -30,18 +32,15 @@ class BooleanType extends FormChoiceType
         $this->translator = $translator;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public function getDefaultOptions()
+    public function setDefaultOptions(OptionsResolverInterface $resolver)
     {
-        $options = parent::getDefaultOptions();
-
-        $options['choices'] = array(
-            self::TYPE_YES  => $this->translator->trans('label_type_yes', array(), 'SonataAdminBundle'),
-            self::TYPE_NO   => $this->translator->trans('label_type_no', array(), 'SonataAdminBundle'),
-        );
-
-        return $options;
+        parent::setDefaultOptions($resolver);
+        
+        $resolver->setDefaults(array(
+            'choices' => array(
+                self::TYPE_YES  => $this->translator->trans('label_type_yes', array(), 'SonataAdminBundle'),
+                self::TYPE_NO   => $this->translator->trans('label_type_no', array(), 'SonataAdminBundle')
+            )
+        ));
     }
 }

+ 5 - 3
Form/Type/CollectionType.php

@@ -15,6 +15,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 CollectionType extends AbstractType
@@ -34,13 +36,13 @@ class CollectionType extends AbstractType
         $builder->addEventSubscriber($listener);
     }
 
-    public function getDefaultOptions()
+    public function setDefaultOptions(OptionsResolverInterface $resolver)
     {
-        return array(
+        $resolver->setDefaults(array(
             'modifiable'    => false,
             'type'          => 'text',
             'type_options'  => array()
-        );
+        ));
     }
 
     /**