From 6b6571cd2835aea1f3c3b8b74d6a4a80e0a4f976 Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Tue, 4 Sep 2012 11:40:41 +1200 Subject: [PATCH] BUGFIX: Only rely on request var ParentID, instead of using both $this->currentPage() and the request var. This will hopefully fix issues around the parent ID getting lost. --- code/controllers/CMSPageAddController.php | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/code/controllers/CMSPageAddController.php b/code/controllers/CMSPageAddController.php index 49749426..6bb1a9a5 100644 --- a/code/controllers/CMSPageAddController.php +++ b/code/controllers/CMSPageAddController.php @@ -15,9 +15,7 @@ class CMSPageAddController extends CMSPageEditController { /** * @return Form */ - public function AddForm() { - $record = $this->currentPage(); - + function AddForm() { $pageTypes = array(); foreach($this->PageTypes() as $type) { $html = sprintf('%s%s', @@ -39,7 +37,6 @@ class CMSPageAddController extends CMSPageEditController { $childTitle = _t('CMSPageAddController.ParentMode_child', 'Under another page'); $fields = new FieldList( - // 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', @@ -72,21 +69,24 @@ class CMSPageAddController extends CMSPageEditController { _t( 'CMSMain.AddPageRestriction', 'Note: Some page types are not allowed for this selection' - ) + ) ) ) ); + // TODO Re-enable search once it allows for HTML title display, // see http://open.silverstripe.org/ticket/7455 // $parentField->setShowSearch(true); - $parentModeField->setValue($this->request->getVar('ParentID') ? 'child' : 'top'); + $parentModeField->addExtraClass('parent-mode'); // 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(); - if($record && $record->URLSegment != $homepageSegment) { - $parentField->setValue($record->ID); + if($parentID = $this->request->getVar('ParentID')) { + $parentModeField->setValue('child'); + $parentField->setValue((int)$parentID); + } else { + $parentModeField->setValue('top'); } $actions = new FieldList( @@ -102,10 +102,6 @@ class CMSPageAddController extends CMSPageEditController { $form->addExtraClass('cms-add-form stacked cms-content center cms-edit-form ' . $this->BaseCSSClasses()); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); - if($parentID = $this->request->getVar('ParentID')) { - $form->Fields()->dataFieldByName('ParentID')->setValue((int)$parentID); - } - return $form; }