Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Add validator related deprecation notices #6633

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ UPGRADE 3.x
UPGRADE FROM 3.xx to 3.xx
=========================

### Deprecated `AdminInterface::getValidator()` and `AdminInterface::setValidator()` methods, `AbstractAdmin::$validator` property.
franmomu marked this conversation as resolved.
Show resolved Hide resolved

Methods are deprecated without replacement.

UPGRADE FROM 3.81 to 3.82
=========================

Expand Down
19 changes: 19 additions & 0 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A
protected $securityHandler;

/**
* NEXT_MAJOR: Remove this property.
*
tambait marked this conversation as resolved.
Show resolved Hide resolved
* @var ValidatorInterface
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
protected $validator;

Expand Down Expand Up @@ -2849,6 +2853,11 @@ public function id($model)
return $this->getNormalizedIdentifier($model);
}

/**
* NEXT_MAJOR: Remove this method.
tambait marked this conversation as resolved.
Show resolved Hide resolved
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
public function setValidator($validator)
{
// NEXT_MAJOR: Move ValidatorInterface check to method signature
Expand All @@ -2862,8 +2871,18 @@ public function setValidator($validator)
$this->validator = $validator;
}

/**
* NEXT_MAJOR: Remove this method.
tambait marked this conversation as resolved.
Show resolved Hide resolved
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
public function getValidator()
{
@trigger_error(sprintf(
'The %s method is deprecated since version 3.x and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);

return $this->validator;
}

Expand Down
8 changes: 8 additions & 0 deletions src/Admin/AdminInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,22 @@ public function getNormalizedIdentifier($model);
public function id($model);

/**
* NEXT_MAJOR: remove this method.
*
* @param ValidatorInterface $validator
*
* @return void
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
public function setValidator($validator);

/**
* NEXT_MAJOR: remove this method.
*
* @return ValidatorInterface
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
public function getValidator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function applyConfigurationFromAttribute(Definition $definition, array $a
'translator',
'configuration_pool',
'router',
'validator',
'validator', //NEXT_MAJOR: Remove this line
'security_handler',
'menu_factory',
'route_builder',
Expand Down Expand Up @@ -281,7 +281,7 @@ public function applyDefaults(ContainerBuilder $container, $serviceId, array $at
'translator' => 'translator',
'configuration_pool' => 'sonata.admin.pool',
'route_generator' => 'sonata.admin.route.default_generator',
'validator' => 'validator',
'validator' => 'validator', //NEXT_MAJOR: Remove this line
'security_handler' => 'sonata.admin.security.handler',
'menu_factory' => 'knp_menu.factory',
'route_builder' => 'sonata.admin.route.path_info'.
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ public function getConfigTreeBuilder()
->scalarNode('translator')->defaultNull()->end()
->scalarNode('configuration_pool')->defaultNull()->end()
->scalarNode('route_generator')->defaultNull()->end()
// NEXT_MAJOR: remove validator option
->scalarNode('validator')->defaultNull()->end()
->scalarNode('security_handler')->defaultNull()->end()
->scalarNode('label')->defaultNull()->end()
Expand Down
9 changes: 9 additions & 0 deletions tests/Admin/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,11 @@ public function testGetFormTheme(): void
$this->assertSame(['FooTheme'], $admin->getFormTheme());
}

/**
* NEXT_MAJOR: remove this method.
*
* @group legacy
*/
public function testGetValidator(): void
{
$admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController');
Expand All @@ -963,6 +968,9 @@ public function testGetValidator(): void
$validator = $this->getMockForAbstractClass(ValidatorInterface::class);

$admin->setValidator($validator);

$this->expectDeprecation('The Sonata\AdminBundle\Admin\AbstractAdmin::getValidator method is deprecated since version 3.x and will be removed in 4.0.');

$this->assertSame($validator, $admin->getValidator());
}

Expand Down Expand Up @@ -2838,6 +2846,7 @@ public function testAdminAvoidInifiniteLoop(): void
$pager = $this->createStub(PagerInterface::class);
$admin->setDatagridBuilder(new DatagridBuilder($formFactory, $pager));

// NEXT_MAJOR: remove the following 3 lines
$validator = $this->createMock(ValidatorInterface::class);
$validator->method('getMetadataFor')->willReturn($this->createStub(MemberMetadata::class));
$admin->setValidator($validator);
Expand Down