Browse files

ENHANCEMENT Allowing to add pages from main interface, in addition to…

… dialog triggered from admin/pages (through CMSPageAddController)
  • Loading branch information...
1 parent dccbb8b commit 0d008b64962ed2973003392e1283b6452375d657 @chillu chillu committed Dec 20, 2011
View
3 _config.php
@@ -34,4 +34,5 @@
CMSMenu::remove_menu_item('CMSPageEditController');
CMSMenu::remove_menu_item('CMSPageSettingsController');
CMSMenu::remove_menu_item('CMSPageHistoryController');
-CMSMenu::remove_menu_item('CMSPageReportsController');
+CMSMenu::remove_menu_item('CMSPageReportsController');
+CMSMenu::remove_menu_item('CMSPageAddController');
View
5 code/controllers/CMSMain.php
@@ -653,13 +653,16 @@ public function doAdd($data, $form) {
$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'])) {
return $record->ID;
} else if(Director::is_ajax()) {
$form = $this->getEditForm($record->ID);
return $form->forTemplate();
} else {
- return $this->redirect(Controller::join_links($this->Link('show'), $record->ID));
+ return $this->redirect($link);
}
}
View
27 code/controllers/CMSPageAddController.php
@@ -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
37 templates/Includes/CMSPageAddController_Content.ss
@@ -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 %>

0 comments on commit 0d008b6

Please sign in to comment.