Skip to content

Commit

Permalink
Merge pull request sonata-project#3356 from WouterJ/issue_3248
Browse files Browse the repository at this point in the history
Update for Symfony 2.8 deprecations
  • Loading branch information
rande committed Nov 13, 2015
2 parents 6d001c3 + 35d7197 commit b19feb9
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
3 changes: 2 additions & 1 deletion Form/FormMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down
19 changes: 14 additions & 5 deletions Form/Type/AclMatrixType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';
}
Expand Down
10 changes: 10 additions & 0 deletions Form/Type/AdminType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
10 changes: 10 additions & 0 deletions Form/Type/ChoiceFieldMaskType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
10 changes: 10 additions & 0 deletions Form/Type/CollectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
10 changes: 10 additions & 0 deletions Form/Type/Filter/ChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
10 changes: 10 additions & 0 deletions Form/Type/Filter/DateRangeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
10 changes: 10 additions & 0 deletions Form/Type/Filter/DateTimeRangeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
10 changes: 10 additions & 0 deletions Form/Type/Filter/DateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
10 changes: 10 additions & 0 deletions Form/Type/Filter/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
10 changes: 10 additions & 0 deletions Form/Type/Filter/DefaultType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
12 changes: 10 additions & 2 deletions Form/Type/Filter/NumberType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
10 changes: 10 additions & 0 deletions Form/Type/ModelHiddenType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
10 changes: 10 additions & 0 deletions Form/Type/ModelReferenceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
10 changes: 10 additions & 0 deletions Form/Type/ModelType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
10 changes: 10 additions & 0 deletions Form/Type/ModelTypeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down

0 comments on commit b19feb9

Please sign in to comment.