diff --git a/UPGRADE-3.x.md b/UPGRADE-3.x.md index bc688a8b225..5f97783c12c 100644 --- a/UPGRADE-3.x.md +++ b/UPGRADE-3.x.md @@ -4,6 +4,10 @@ UPGRADE 3.x UPGRADE FROM 3.xx to 3.xx ========================= +### Deprecated `AdminInterface::getValidator()` and `AdminInterface::setValidator()` methods, `AbstractAdmin::$validator` property. + +Methods are deprecated without replacement. + ### Sonata\AdminBundle\Admin\Pool - Passing a `Symfony\Component\PropertyAccess\PropertyAccessorInterface` instance as 4 argument instantiating diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 96c0f968756..f6c1f14beb9 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -392,7 +392,11 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A protected $securityHandler; /** + * NEXT_MAJOR: Remove this property. + * * @var ValidatorInterface + * + * @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0 */ protected $validator; @@ -2849,6 +2853,11 @@ public function id($model) return $this->getNormalizedIdentifier($model); } + /** + * NEXT_MAJOR: Remove this method. + * + * @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 @@ -2862,8 +2871,18 @@ public function setValidator($validator) $this->validator = $validator; } + /** + * NEXT_MAJOR: Remove this method. + * + * @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; } diff --git a/src/Admin/AdminInterface.php b/src/Admin/AdminInterface.php index 6555e1398eb..69d0098a7d0 100644 --- a/src/Admin/AdminInterface.php +++ b/src/Admin/AdminInterface.php @@ -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(); diff --git a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php index a4f580ef6e1..2c4f025bfeb 100644 --- a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php +++ b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php @@ -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', @@ -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'. diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index cbb3a0fca8e..c9905c7fa72 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -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() diff --git a/tests/Admin/AdminTest.php b/tests/Admin/AdminTest.php index c34c5c59031..fbdf3ce55c3 100644 --- a/tests/Admin/AdminTest.php +++ b/tests/Admin/AdminTest.php @@ -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'); @@ -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()); } @@ -2840,6 +2848,7 @@ public function testAdminAvoidInifiniteLoop(): void $validator = $this->createMock(ValidatorInterface::class); $validator->method('getMetadataFor')->willReturn($this->createStub(MemberMetadata::class)); + $admin->setValidator($validator); $routeGenerator = $this->createStub(RouteGeneratorInterface::class);