diff --git a/UPGRADE-3.x.md b/UPGRADE-3.x.md index da09a687fc..3b9479190d 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. + UPGRADE FROM 3.81 to 3.82 ========================= diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 19f85587f4..c9fc74c5aa 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 407340588a..dfc210504a 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 a4f580ef6e..2c4f025bfe 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 cbb3a0fca8..c9905c7fa7 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 c34c5c5903..a209d36a47 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()); } @@ -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);