浏览代码

Merge pull request #3356 from WouterJ/issue_3248

Update for Symfony 2.8 deprecations
Thomas 9 年之前
父节点
当前提交
b19feb9c22

+ 7 - 1
DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php

@@ -224,7 +224,13 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
         $definition = $container->getDefinition($serviceId);
         $settings = $container->getParameter('sonata.admin.configuration.admin_services');
 
-        $definition->setScope(ContainerInterface::SCOPE_PROTOTYPE);
+        if (method_exists($definition, 'setShared')) {
+            // Symfony 2.8+
+            $definition->setShared(true);
+        } else {
+            // For Symfony <2.8 compatibility
+            $definition->setScope(ContainerInterface::SCOPE_PROTOTYPE);
+        }
 
         $manager_type = $attributes['manager_type'];
 

+ 2 - 1
Form/FormMapper.php

@@ -80,7 +80,8 @@ class FormMapper extends BaseGroupedMapper
 
         // change `collection` to `sonata_type_native_collection` form type to
         // avoid BC break problems
-        if ($type == 'collection') {
+        if ($type === 'collection' || $type === 'Symfony\Component\Form\Extension\Core\Type\CollectionType') {
+            // the field name is used to preserve Symfony <2.8 compatibility, the FQCN should be used instead
             $type = 'sonata_type_native_collection';
         }
 

+ 14 - 5
Form/Type/AclMatrixType.php

@@ -13,7 +13,6 @@ namespace Sonata\AdminBundle\Form\Type;
 
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\FormBuilderInterface;
-use Symfony\Component\HttpKernel\Kernel;
 use Symfony\Component\OptionsResolver\OptionsResolver;
 use Symfony\Component\OptionsResolver\OptionsResolverInterface;
 use Symfony\Component\Security\Core\User\UserInterface;
@@ -61,21 +60,31 @@ class AclMatrixType extends AbstractType
             'acl_value',
         ));
 
-        if (version_compare(Kernel::VERSION, '2.6', '<')) {
+        if (method_exists($resolver, 'setDefined')) {
+            $resolver->setAllowedTypes('permissions', 'array');
+            $resolver->setAllowedTypes('acl_value', array('string', '\Symfony\Component\Security\Core\User\UserInterface'));
+        } else {
             $resolver->setAllowedTypes(array(
                 'permissions' => 'array',
                 'acl_value'   => array('string', '\Symfony\Component\Security\Core\User\UserInterface'),
             ));
-        } else {
-            $resolver->setAllowedTypes('permissions', 'array');
-            $resolver->setAllowedTypes('acl_value', array('string', '\Symfony\Component\Security\Core\User\UserInterface'));
         }
     }
 
     /**
      * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_acl_matrix';
     }

+ 10 - 0
Form/Type/AdminType.php

@@ -160,8 +160,18 @@ class AdminType extends AbstractType
 
     /**
      * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_admin';
     }

+ 10 - 0
Form/Type/ChoiceFieldMaskType.php

@@ -82,8 +82,18 @@ class ChoiceFieldMaskType extends AbstractType
 
     /**
      * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_choice_field_mask';
     }

+ 10 - 0
Form/Type/CollectionType.php

@@ -31,8 +31,18 @@ class CollectionType extends AbstractType
 
     /**
      * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_native_collection';
     }

+ 10 - 0
Form/Type/Filter/ChoiceType.php

@@ -42,8 +42,18 @@ class ChoiceType extends AbstractType
 
     /**
      * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_filter_choice';
     }

+ 10 - 0
Form/Type/Filter/DateRangeType.php

@@ -39,8 +39,18 @@ class DateRangeType extends AbstractType
 
     /**
      * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_filter_date_range';
     }

+ 10 - 0
Form/Type/Filter/DateTimeRangeType.php

@@ -39,8 +39,18 @@ class DateTimeRangeType extends AbstractType
 
     /**
      * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_filter_datetime_range';
     }

+ 10 - 0
Form/Type/Filter/DateTimeType.php

@@ -50,8 +50,18 @@ class DateTimeType extends AbstractType
 
     /**
      * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_filter_datetime';
     }

+ 10 - 0
Form/Type/Filter/DateType.php

@@ -50,8 +50,18 @@ class DateType extends AbstractType
 
     /**
      * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_filter_date';
     }

+ 10 - 0
Form/Type/Filter/DefaultType.php

@@ -25,8 +25,18 @@ class DefaultType extends AbstractType
 {
     /**
      * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_filter_default';
     }

+ 10 - 2
Form/Type/Filter/NumberType.php

@@ -45,11 +45,19 @@ class NumberType extends AbstractType
     }
 
     /**
-     * Returns the name of this type.
+     * {@inheritdoc}
      *
-     * @return string The name of this type
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_filter_number';
     }

+ 10 - 0
Form/Type/ModelHiddenType.php

@@ -65,8 +65,18 @@ class ModelHiddenType extends AbstractType
 
     /**
      * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_model_hidden';
     }

+ 10 - 0
Form/Type/ModelReferenceType.php

@@ -64,8 +64,18 @@ class ModelReferenceType extends AbstractType
 
     /**
      * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_model_reference';
     }

+ 10 - 0
Form/Type/ModelType.php

@@ -134,8 +134,18 @@ class ModelType extends AbstractType
 
     /**
      * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_model';
     }

+ 10 - 0
Form/Type/ModelTypeList.php

@@ -87,8 +87,18 @@ class ModelTypeList extends AbstractType
 
     /**
      * {@inheritdoc}
+     *
+     * @todo Remove when dropping Symfony <2.8 support
      */
     public function getName()
+    {
+        return $this->getBlockPrefix();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getBlockPrefix()
     {
         return 'sonata_type_model_list';
     }