Explorar el Código

Fix bad class name for ModelListType

Sullivan SENECHAL hace 9 años
padre
commit
ec654e8183

+ 1 - 1
DependencyInjection/SonataAdminExtension.php

@@ -269,7 +269,7 @@ class SonataAdminExtension extends Extension implements PrependExtensionInterfac
             'Sonata\\AdminBundle\\Form\\Type\\Filter\\NumberType',
             'Sonata\\AdminBundle\\Form\\Type\\ModelReferenceType',
             'Sonata\\AdminBundle\\Form\\Type\\ModelType',
-            'Sonata\\AdminBundle\\Form\\Type\\ModelTypeList',
+            'Sonata\\AdminBundle\\Form\\Type\\ModelListType',
             'Sonata\\AdminBundle\\Guesser\\TypeGuesserChain',
             'Sonata\\AdminBundle\\Guesser\\TypeGuesserInterface',
             'Sonata\\AdminBundle\\Model\\AuditManager',

+ 105 - 0
Form/Type/ModelListType.php

@@ -0,0 +1,105 @@
+<?php
+
+/*
+ * This file is part of the Sonata Project package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\AdminBundle\Form\Type;
+
+use Sonata\AdminBundle\Form\DataTransformer\ModelToIdTransformer;
+use Symfony\Component\Form\AbstractType;
+use Symfony\Component\Form\FormBuilderInterface;
+use Symfony\Component\Form\FormInterface;
+use Symfony\Component\Form\FormView;
+use Symfony\Component\OptionsResolver\OptionsResolver;
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+
+/**
+ * This type is used to render an hidden input text and 3 links
+ *   - an add form modal
+ *   - a list modal to select the targeted entities
+ *   - a clear selection link.
+ */
+class ModelListType extends AbstractType
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function buildForm(FormBuilderInterface $builder, array $options)
+    {
+        $builder
+            ->resetViewTransformers()
+            ->addViewTransformer(new ModelToIdTransformer($options['model_manager'], $options['class']));
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function buildView(FormView $view, FormInterface $form, array $options)
+    {
+        if (isset($view->vars['sonata_admin'])) {
+            // set the correct edit mode
+            $view->vars['sonata_admin']['edit'] = 'list';
+        }
+        $view->vars['btn_add'] = $options['btn_add'];
+        $view->vars['btn_list'] = $options['btn_list'];
+        $view->vars['btn_delete'] = $options['btn_delete'];
+        $view->vars['btn_catalogue'] = $options['btn_catalogue'];
+    }
+
+    /**
+     * {@inheritdoc}
+     *
+     * @todo Remove it when bumping requirements to SF 2.7+
+     */
+    public function setDefaultOptions(OptionsResolverInterface $resolver)
+    {
+        $this->configureOptions($resolver);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function configureOptions(OptionsResolver $resolver)
+    {
+        $resolver->setDefaults(array(
+            'model_manager' => null,
+            'class' => null,
+            'btn_add' => 'link_add',
+            'btn_list' => 'link_list',
+            'btn_delete' => 'link_delete',
+            'btn_catalogue' => 'SonataAdminBundle',
+        ));
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getParent()
+    {
+        return 'text';
+    }
+
+    /**
+     * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
+     */
+    public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
+    {
+        return 'sonata_type_model_list';
+    }
+}

+ 8 - 83
Form/Type/ModelTypeList.php

@@ -11,95 +11,20 @@
 
 namespace Sonata\AdminBundle\Form\Type;
 
-use Sonata\AdminBundle\Form\DataTransformer\ModelToIdTransformer;
-use Symfony\Component\Form\AbstractType;
-use Symfony\Component\Form\FormBuilderInterface;
-use Symfony\Component\Form\FormInterface;
-use Symfony\Component\Form\FormView;
-use Symfony\Component\OptionsResolver\OptionsResolver;
-use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+@trigger_error(
+    'The '.__NAMESPACE__.'\ModelTypeList class is deprecated since version 3.x and will be removed in 4.0.'
+    .' Use '.__NAMESPACE__.'\ModelListType instead.',
+    E_USER_DEPRECATED
+);
 
 /**
  * This type is used to render an hidden input text and 3 links
  *   - an add form modal
  *   - a list modal to select the targeted entities
  *   - a clear selection link.
+ *
+ * @deprecated since version 3.x, to be removed in 4.0. Use ModelListType instead
  */
-class ModelTypeList extends AbstractType
+class ModelTypeList extends ModelListType
 {
-    /**
-     * {@inheritdoc}
-     */
-    public function buildForm(FormBuilderInterface $builder, array $options)
-    {
-        $builder
-            ->resetViewTransformers()
-            ->addViewTransformer(new ModelToIdTransformer($options['model_manager'], $options['class']));
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function buildView(FormView $view, FormInterface $form, array $options)
-    {
-        if (isset($view->vars['sonata_admin'])) {
-            // set the correct edit mode
-            $view->vars['sonata_admin']['edit'] = 'list';
-        }
-        $view->vars['btn_add'] = $options['btn_add'];
-        $view->vars['btn_list'] = $options['btn_list'];
-        $view->vars['btn_delete'] = $options['btn_delete'];
-        $view->vars['btn_catalogue'] = $options['btn_catalogue'];
-    }
-
-    /**
-     * {@inheritdoc}
-     *
-     * @todo Remove it when bumping requirements to SF 2.7+
-     */
-    public function setDefaultOptions(OptionsResolverInterface $resolver)
-    {
-        $this->configureOptions($resolver);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function configureOptions(OptionsResolver $resolver)
-    {
-        $resolver->setDefaults(array(
-            'model_manager' => null,
-            'class' => null,
-            'btn_add' => 'link_add',
-            'btn_list' => 'link_list',
-            'btn_delete' => 'link_delete',
-            'btn_catalogue' => 'SonataAdminBundle',
-        ));
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getParent()
-    {
-        return 'text';
-    }
-
-    /**
-     * {@inheritdoc}
-     *
-     * @todo Remove when dropping Symfony <2.8 support
-     */
-    public function getName()
-    {
-        return $this->getBlockPrefix();
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getBlockPrefix()
-    {
-        return 'sonata_type_model_list';
-    }
 }

+ 5 - 0
Tests/Form/Type/ModelTypeListTest.php

@@ -15,6 +15,11 @@ use Sonata\AdminBundle\Form\Type\ModelTypeList;
 use Symfony\Component\Form\Test\TypeTestCase;
 use Symfony\Component\OptionsResolver\OptionsResolver;
 
+/**
+ * @group legacy
+ *
+ * NEXT_MAJOR: Change test class name and content according to the renaming.
+ */
 class ModelTypeListTest extends TypeTestCase
 {
     public function testGetDefaultOptions()

+ 6 - 0
UPGRADE-3.x.md

@@ -1,6 +1,12 @@
 UPGRADE 3.x
 ===========
 
+## Deprecated ModelTypeList for rename
+
+The `Sonata\AdminBundle\Form\Type\ModelTypeList` class is now deprecated.
+
+Use `Sonata\AdminBundle\Form\Type\ModelListType` instead.
+
 UPGRADE FROM 3.2 to 3.3
 =======================