From a4704c75e9b6f5cc2ac4567471782847e22b24ae Mon Sep 17 00:00:00 2001 From: Jorrit Schippers Date: Tue, 29 Sep 2020 15:14:26 +0200 Subject: [PATCH] Prevent deprecation notice when AdminInterface->isCurrentChild() is implemented --- src/Admin/AbstractAdmin.php | 14 +++++++++----- tests/Admin/AdminTest.php | 5 ----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 96dae0bddf..2a6819c6c0 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -2435,12 +2435,16 @@ public function isCurrentChild(): bool */ public function getCurrentChildAdmin() { - foreach ($this->children as $children) { + foreach ($this->children as $child) { // NEXT_MAJOR: Remove method_exists check and delete elseif case - if (method_exists($children, 'isCurrentChild') && $children->isCurrentChild()) { - return $children; - } elseif ($children->getCurrentChild()) { - return $children; + if (method_exists($child, 'isCurrentChild')) { + if ($child->isCurrentChild()) { + return $child; + } + } else { + if ($child->getCurrentChild()) { + return $child; + } } } diff --git a/tests/Admin/AdminTest.php b/tests/Admin/AdminTest.php index 502f1b27ac..bd5750e70b 100644 --- a/tests/Admin/AdminTest.php +++ b/tests/Admin/AdminTest.php @@ -2678,11 +2678,6 @@ public function testGetChildDepth(): void $this->assertSame(2, $commentVoteAdmin->getChildDepth()); } - /** - * @group legacy - * - * @expectedDeprecation The Sonata\AdminBundle\Admin\AbstractAdmin::getCurrentChild() method is deprecated since version 3.65 and will be removed in 4.0. Use Sonata\AdminBundle\Admin\AbstractAdmin::isCurrentChild() instead. - */ public function testGetCurrentLeafChildAdmin(): void { $postAdmin = new PostAdmin(