From 1b3a4aea96873792b59ae0788057a7e340d13f50 Mon Sep 17 00:00:00 2001 From: Nic Horstmeier Date: Thu, 16 May 2019 19:53:59 -0500 Subject: [PATCH] BUGFIX Page Type listed in Page Type dropdown when $can_be_root is false resolves #2430 --- code/Model/SiteTree.php | 5 +++++ tests/php/Model/SiteTreeTest.php | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/code/Model/SiteTree.php b/code/Model/SiteTree.php index f0c768cf..bb8b6cb3 100755 --- a/code/Model/SiteTree.php +++ b/code/Model/SiteTree.php @@ -2567,6 +2567,11 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi foreach ($classes as $class) { $instance = singleton($class); + //if the current page is root and the instance can't be, exclude + if (!$instance->config()->get('can_be_root') && $this->ParentID == 0) { + continue; + } + // if the current page type is this the same as the class type always show the page type in the list if ($this->ClassName != $instance->ClassName) { if ($instance instanceof HiddenClass) { diff --git a/tests/php/Model/SiteTreeTest.php b/tests/php/Model/SiteTreeTest.php index 0aa2db16..384df5a4 100644 --- a/tests/php/Model/SiteTreeTest.php +++ b/tests/php/Model/SiteTreeTest.php @@ -1272,6 +1272,13 @@ class SiteTreeTest extends SapphireTest $this->loginWithPermission('CMS_ACCESS_CMSMain'); $this->assertArrayHasKey(SiteTreeTest_ClassA::class, $method->invoke($sitetree)); + $this->logInWithPermission('ADMIN'); + $rootPage = $this->objFromFixture(Page::class, 'home'); + $nonRootPage = $this->objFromFixture(Page::class, 'staff'); + + $this->assertArrayNotHasKey(SiteTreeTest_NotRoot::class, $method->invoke($rootPage)); + $this->assertArrayHasKey(SiteTreeTest_NotRoot::class, $method->invoke($nonRootPage)); + Security::setCurrentUser(null); }