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.

This commit is contained in:
Andrew O'Neil 2012-09-04 11:40:41 +12:00 committed by Ingo Schommer
parent 98e824bced
commit 6b6571cd28

View File

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