From 463ee0c5f7d6e1b792e201dc32365a260dacc095 Mon Sep 17 00:00:00 2001 From: Mark Stephens Date: Fri, 9 Mar 2012 17:39:41 +1300 Subject: [PATCH] ENHANCEMENT: added option to add page to top level --- code/controllers/CMSMain.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php index 992bcd8d..10a5bb26 100644 --- a/code/controllers/CMSMain.php +++ b/code/controllers/CMSMain.php @@ -620,10 +620,13 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr return $form->forTemplate(); } - public function doAdd($data, $form) { $className = isset($data['PageType']) ? $data['PageType'] : "Page"; + $parentMode = isset($data['ParentModeField']) ? $data['ParentModeField'] : "top"; $parentID = isset($data['ParentID']) ? (int)$data['ParentID'] : 0; + + if ($parentMode == "top") $parentID = 0; + $suffix = isset($data['Suffix']) ? "-" . $data['Suffix'] : null; if(!$parentID && isset($data['Parent'])) { @@ -1069,10 +1072,17 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr // new HiddenField("ParentID", false, ($this->parentRecord) ? $this->parentRecord->ID : null), // TODO Should be part of the form attribute, but not possible in current form API $hintsField = new LiteralField('Hints', sprintf('', $this->SiteTreeHints())), - $parentField = new TreeDropdownField( - "ParentID", - sprintf($numericLabelTmpl, 1, _t('CMSMain.AddFormParentLabel', 'Choose parent')), - 'SiteTree' + new LiteralField('PageModeHeader', sprintf($numericLabelTmpl, 1, _t('CMSMain.ChoosePageParentMode', 'Choose where to create this page'))), + $parentModeField = new SelectionGroup( + "ParentModeField", + array( + "top//Top level" => null, //new LiteralField("Dummy", ''), + "child//Under another page" => $parentField = new TreeDropdownField( + "ParentID", + "", + 'SiteTree' + ) + ) ), $typeField = new OptionsetField( "PageType", @@ -1083,6 +1093,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr ); $parentField->setShowSearch(true); + $parentModeField->setValue("child"); + // CMSMain->currentPageID() automatically sets the homepage, // which we need to counteract in the default selection (which should default to root, ID=0) $homepageSegment = RootURLController::get_homepage_link();