ENHANCEMENT Allowing to add pages from main interface, in addition to dialog triggered from admin/pages (through CMSPageAddController)

This commit is contained in:
Ingo Schommer 2011-12-20 15:57:02 +01:00
parent dccbb8b48a
commit 0d008b6496
4 changed files with 70 additions and 2 deletions

View File

@ -34,4 +34,5 @@ Object::add_extension('File', 'SiteTreeFileExtension');
CMSMenu::remove_menu_item('CMSPageEditController'); CMSMenu::remove_menu_item('CMSPageEditController');
CMSMenu::remove_menu_item('CMSPageSettingsController'); CMSMenu::remove_menu_item('CMSPageSettingsController');
CMSMenu::remove_menu_item('CMSPageHistoryController'); CMSMenu::remove_menu_item('CMSPageHistoryController');
CMSMenu::remove_menu_item('CMSPageReportsController'); CMSMenu::remove_menu_item('CMSPageReportsController');
CMSMenu::remove_menu_item('CMSPageAddController');

View File

@ -653,13 +653,16 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$form = $this->getEditForm($record->ID); $form = $this->getEditForm($record->ID);
$link = Controller::join_links(singleton('CMSPageEditController')->Link('show'), $record->ID);
$this->getResponse()->addHeader('X-ControllerURL', $link);
if(isset($data['returnID'])) { if(isset($data['returnID'])) {
return $record->ID; return $record->ID;
} else if(Director::is_ajax()) { } else if(Director::is_ajax()) {
$form = $this->getEditForm($record->ID); $form = $this->getEditForm($record->ID);
return $form->forTemplate(); return $form->forTemplate();
} else { } else {
return $this->redirect(Controller::join_links($this->Link('show'), $record->ID)); return $this->redirect($link);
} }
} }

View File

@ -0,0 +1,27 @@
<?php
class CMSPageAddController extends CMSMain {
static $url_segment = 'page/add';
static $url_rule = '/$Action/$ID/$OtherID';
static $url_priority = 42;
static $menu_title = 'Add page';
function AddForm() {
$form = parent::AddForm();
$form->addExtraClass('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;
}
function doAdd($data, $form) {
$return = parent::doAdd($data, $form);
$this->getResponse()->addHeader('X-Controller', 'CMSPageEditController');
return $return;
}
}

View File

@ -0,0 +1,37 @@
<% with AddForm %>
<form $FormAttributes data-layout="{type: 'border'}">
<div class="cms-content-header north">
<div>
<h2><% _t('CMSAddPageController.Title','Add pages') %></h2>
</div>
</div>
<div class="cms-content-fields center cms-panel-content cms-panel-padded">
<% if Message %>
<p id="{$FormName}_error" class="message $MessageType">$Message</p>
<% else %>
<p id="{$FormName}_error" class="message $MessageType" style="display: none"></p>
<% end_if %>
<fieldset>
<% if Legend %><legend>$Legend</legend><% end_if %>
<% control Fields %>
$FieldHolder
<% end_control %>
</fieldset>
</div>
<div class="cms-content-actions south">
<% if Actions %>
<div class="Actions">
<% control Actions %>
$Field
<% end_control %>
</div>
<% end_if %>
</div>
</form>
<% end_with %>