diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index aa804961..792c0e17 100755 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -1019,7 +1019,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid } // Fall over to inherited permissions - if($parent) { + if($parent && $parent->exists()) { return $parent->canAddChildren($member); } else { // This doesn't necessarily mean we are creating a root page, but that diff --git a/javascript/CMSMain.AddForm.js b/javascript/CMSMain.AddForm.js index 2681d7ab..683abcc0 100644 --- a/javascript/CMSMain.AddForm.js +++ b/javascript/CMSMain.AddForm.js @@ -52,7 +52,7 @@ ? (parentTree.getValue() || this.getParentID()) : null, newClassName = metadata ? metadata.ClassName : null, - hintKey = (newClassName && parentMode === 'child') + hintKey = (newClassName && parentMode === 'child' && id) ? newClassName : 'Root', hint = (typeof hints[hintKey] !== 'undefined') ? hints[hintKey] : null, diff --git a/tests/model/SiteTreeTest.php b/tests/model/SiteTreeTest.php index 93ad7157..3ded8572 100644 --- a/tests/model/SiteTreeTest.php +++ b/tests/model/SiteTreeTest.php @@ -545,6 +545,10 @@ class SiteTreeTest extends SapphireTest { $this->assertTrue(singleton('SiteTreeTest_ClassA')->canCreate(null)); $this->assertFalse(singleton('SiteTreeTest_ClassA')->canCreate(null, array('Parent' => $parentB))); $this->assertTrue(singleton('SiteTreeTest_ClassC')->canCreate(null, array('Parent' => $parentB))); + + // Test creation underneath a parent which doesn't exist in the database. This should + // fall back to checking whether the user can create pages at the root of the site + $this->assertTrue(singleton('SiteTree')->canCreate(null, array('Parent' => singleton('SiteTree')))); } public function testEditPermissionsOnDraftVsLive() {