From 35d7197dcf18aca9b6d03e788d0d3138cf082262 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sun, 11 Oct 2015 14:08:50 +0200 Subject: [PATCH] Fix some 2.8 deprecation notices --- .../AddDependencyCallsCompilerPass.php | 8 +++++++- Form/FormMapper.php | 3 ++- Form/Type/AclMatrixType.php | 19 ++++++++++++++----- Form/Type/AdminType.php | 10 ++++++++++ Form/Type/ChoiceFieldMaskType.php | 10 ++++++++++ Form/Type/CollectionType.php | 10 ++++++++++ Form/Type/Filter/ChoiceType.php | 10 ++++++++++ Form/Type/Filter/DateRangeType.php | 10 ++++++++++ Form/Type/Filter/DateTimeRangeType.php | 10 ++++++++++ Form/Type/Filter/DateTimeType.php | 10 ++++++++++ Form/Type/Filter/DateType.php | 10 ++++++++++ Form/Type/Filter/DefaultType.php | 10 ++++++++++ Form/Type/Filter/NumberType.php | 12 ++++++++++-- Form/Type/ModelHiddenType.php | 10 ++++++++++ Form/Type/ModelReferenceType.php | 10 ++++++++++ Form/Type/ModelType.php | 10 ++++++++++ Form/Type/ModelTypeList.php | 10 ++++++++++ 17 files changed, 163 insertions(+), 9 deletions(-) diff --git a/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php b/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php index 48a1337d8f..9d9ce5b43f 100644 --- a/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php +++ b/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php @@ -224,7 +224,13 @@ public function applyDefaults(ContainerBuilder $container, $serviceId, array $at $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']; diff --git a/Form/FormMapper.php b/Form/FormMapper.php index a2a95d4d87..3acc60e023 100644 --- a/Form/FormMapper.php +++ b/Form/FormMapper.php @@ -80,7 +80,8 @@ public function add($name, $type = null, array $options = array(), array $fieldD // 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'; } diff --git a/Form/Type/AclMatrixType.php b/Form/Type/AclMatrixType.php index 143efd664d..5a2b06e720 100644 --- a/Form/Type/AclMatrixType.php +++ b/Form/Type/AclMatrixType.php @@ -13,7 +13,6 @@ 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 @@ public function configureOptions(OptionsResolver $resolver) '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'; } diff --git a/Form/Type/AdminType.php b/Form/Type/AdminType.php index 18aaae720e..1fe0595fb5 100644 --- a/Form/Type/AdminType.php +++ b/Form/Type/AdminType.php @@ -160,8 +160,18 @@ protected function getAdmin(array $options) /** * {@inheritdoc} + * + * @todo Remove when dropping Symfony <2.8 support */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'sonata_type_admin'; } diff --git a/Form/Type/ChoiceFieldMaskType.php b/Form/Type/ChoiceFieldMaskType.php index dd4eb23b25..9d800ed6ed 100644 --- a/Form/Type/ChoiceFieldMaskType.php +++ b/Form/Type/ChoiceFieldMaskType.php @@ -82,8 +82,18 @@ public function getParent() /** * {@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'; } diff --git a/Form/Type/CollectionType.php b/Form/Type/CollectionType.php index 8a72266002..95099e3398 100644 --- a/Form/Type/CollectionType.php +++ b/Form/Type/CollectionType.php @@ -31,8 +31,18 @@ public function getParent() /** * {@inheritdoc} + * + * @todo Remove when dropping Symfony <2.8 support */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'sonata_type_native_collection'; } diff --git a/Form/Type/Filter/ChoiceType.php b/Form/Type/Filter/ChoiceType.php index aec0b4f7f2..019a5c657d 100644 --- a/Form/Type/Filter/ChoiceType.php +++ b/Form/Type/Filter/ChoiceType.php @@ -42,8 +42,18 @@ public function __construct(TranslatorInterface $translator) /** * {@inheritdoc} + * + * @todo Remove when dropping Symfony <2.8 support */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'sonata_type_filter_choice'; } diff --git a/Form/Type/Filter/DateRangeType.php b/Form/Type/Filter/DateRangeType.php index e74d8748ff..1ddf770325 100644 --- a/Form/Type/Filter/DateRangeType.php +++ b/Form/Type/Filter/DateRangeType.php @@ -39,8 +39,18 @@ public function __construct(TranslatorInterface $translator) /** * {@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'; } diff --git a/Form/Type/Filter/DateTimeRangeType.php b/Form/Type/Filter/DateTimeRangeType.php index 2ec5559a1e..e41ace7850 100644 --- a/Form/Type/Filter/DateTimeRangeType.php +++ b/Form/Type/Filter/DateTimeRangeType.php @@ -39,8 +39,18 @@ public function __construct(TranslatorInterface $translator) /** * {@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'; } diff --git a/Form/Type/Filter/DateTimeType.php b/Form/Type/Filter/DateTimeType.php index 96bae9e57c..9c89d8860b 100644 --- a/Form/Type/Filter/DateTimeType.php +++ b/Form/Type/Filter/DateTimeType.php @@ -50,8 +50,18 @@ public function __construct(TranslatorInterface $translator) /** * {@inheritdoc} + * + * @todo Remove when dropping Symfony <2.8 support */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'sonata_type_filter_datetime'; } diff --git a/Form/Type/Filter/DateType.php b/Form/Type/Filter/DateType.php index 37bb090f2d..d0a0961652 100644 --- a/Form/Type/Filter/DateType.php +++ b/Form/Type/Filter/DateType.php @@ -50,8 +50,18 @@ public function __construct(TranslatorInterface $translator) /** * {@inheritdoc} + * + * @todo Remove when dropping Symfony <2.8 support */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'sonata_type_filter_date'; } diff --git a/Form/Type/Filter/DefaultType.php b/Form/Type/Filter/DefaultType.php index 0f09b3bb8d..41139c23d5 100644 --- a/Form/Type/Filter/DefaultType.php +++ b/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'; } diff --git a/Form/Type/Filter/NumberType.php b/Form/Type/Filter/NumberType.php index 74c71cae38..f0e308a35d 100644 --- a/Form/Type/Filter/NumberType.php +++ b/Form/Type/Filter/NumberType.php @@ -45,11 +45,19 @@ public function __construct(TranslatorInterface $translator) } /** - * 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'; } diff --git a/Form/Type/ModelHiddenType.php b/Form/Type/ModelHiddenType.php index ebe20c84c9..cc3b71a105 100644 --- a/Form/Type/ModelHiddenType.php +++ b/Form/Type/ModelHiddenType.php @@ -65,8 +65,18 @@ public function getParent() /** * {@inheritdoc} + * + * @todo Remove when dropping Symfony <2.8 support */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'sonata_type_model_hidden'; } diff --git a/Form/Type/ModelReferenceType.php b/Form/Type/ModelReferenceType.php index 053c429ee9..55683e37ab 100644 --- a/Form/Type/ModelReferenceType.php +++ b/Form/Type/ModelReferenceType.php @@ -64,8 +64,18 @@ public function getParent() /** * {@inheritdoc} + * + * @todo Remove when dropping Symfony <2.8 support */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'sonata_type_model_reference'; } diff --git a/Form/Type/ModelType.php b/Form/Type/ModelType.php index 708bf6eeae..5992556aff 100644 --- a/Form/Type/ModelType.php +++ b/Form/Type/ModelType.php @@ -134,8 +134,18 @@ public function getParent() /** * {@inheritdoc} + * + * @todo Remove when dropping Symfony <2.8 support */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'sonata_type_model'; } diff --git a/Form/Type/ModelTypeList.php b/Form/Type/ModelTypeList.php index b9cada1f67..8d833e90d7 100644 --- a/Form/Type/ModelTypeList.php +++ b/Form/Type/ModelTypeList.php @@ -87,8 +87,18 @@ public function getParent() /** * {@inheritdoc} + * + * @todo Remove when dropping Symfony <2.8 support */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'sonata_type_model_list'; }