BUGFIX Page Type listed in Page Type dropdown when $can_be_root is false

resolves #2430
This commit is contained in:
Nic Horstmeier 2019-05-16 19:53:59 -05:00
parent d33e36c032
commit 1b3a4aea96
2 changed files with 12 additions and 0 deletions

View File

@ -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) {

View File

@ -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);
}