Skip to content
Browse files

BUGFIX: Only rely on request var ParentID, instead of using both $thi…

…s->currentPage() and the request var. This will hopefully fix issues around the parent ID getting lost.
  • Loading branch information...
1 parent 98e824b commit 6b6571cd2835aea1f3c3b8b74d6a4a80e0a4f976 @ajoneil ajoneil committed with chillu Sep 4, 2012
Showing with 9 additions and 13 deletions.
  1. +9 −13 code/controllers/CMSPageAddController.php
View
22 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('<span class="page-icon class-%s"></span><strong class="title">%s</strong><span class="description">%s</span>',
@@ -39,7 +37,6 @@ public function AddForm() {
$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 @@ public function AddForm() {
_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 @@ public function AddForm() {
$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;
}

0 comments on commit 6b6571c

Please sign in to comment.
Something went wrong with that request. Please try again.