Permalink
Browse files

API CHANGE Removed LeftAndMain->EditForm(), please use getEditForm() …

…instead

API CHANGE Returning LeftAndMain->EmptyForm() as a welcome/placeholder message from LeftAndMain->getEditForm() if no record is found. Removed this placeholder from LeftAndMain_right.ss
ENHANCEMENT Allowing optional $id parameter in LeftAndMain->getEditForm() (and subclasses)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92710 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent fef2f77 commit dc4375a383324943ea5a6b0c7477a5abbcee4b32 @chillu chillu committed Nov 21, 2009
View
@@ -282,12 +282,14 @@ public function currentPage() {
/**
* Return the form that displays the details of a folder, including a file list and fields for editing the folder name.
*/
- function getEditForm($id) {
+ function getEditForm($id = null) {
if($id && $id != "root") {
$record = DataObject::get_by_id("File", $id);
} else {
$record = singleton("Folder");
}
+
+ if($record && !$record->canView()) return Security::permissionFailure($this);
if($record) {
$fields = $record->getCMSFields();
@@ -314,12 +316,7 @@ function getEditForm($id) {
$form->makeReadonly();
}
} else {
- $form = new Form(
- $this,
- "EditForm",
- new FieldSet(),
- new FieldSet()
- );
+ $form = $this->EmptyForm();
}
return $form;
View
@@ -327,8 +327,12 @@ public function getRecord($id) {
/**
* Calls {@link SiteTree->getCMSFields()}
*/
- public function getEditForm($id) {
- $record = $this->getRecord($id);
+ public function getEditForm($id = null) {
+ // Include JavaScript to ensure HtmlEditorField works.
+ HtmlEditorField::include_js();
+
+ $record = ($id) ? $this->getRecord($id) : null;
+ if($record && !$record->canView()) return Security::permissionFailure($this);
if($record) {
if($record->IsDeletedFromStage) $record->Status = _t('CMSMain.REMOVEDFD',"Removed from the draft site");
@@ -401,19 +405,12 @@ public function getEditForm($id) {
$form->loadDataFrom($siteConfig);
return $form;
} else {
- $form = new Form(
- $this,
- "EditForm",
- new FieldSet(),
- new FieldSet()
- );
+ $form = $this->EmptyForm();
}
return $form;
}
-
-
//------------------------------------------------------------------------------------------//
// Data saving handlers
View
@@ -52,7 +52,7 @@ public function Section() {
return $section;
}
- public function EditForm() {
+ public function getEditForm($id = null) {
$section = $this->Section();
if($section == 'approved') {
View
@@ -339,12 +339,16 @@ static function menu_title_for_class($class) {
}
public function show($request) {
+ $form = $this->getEditForm($request->param('ID'));
+
if(Director::is_ajax()) {
SSViewer::setOption('rewriteHashlinks', false);
- return $this->EditForm()->formHtmlContent();
+ return $form->formHtmlContent();
} else {
// Rendering is handled by template, which will call EditForm() eventually
- return array();
+ return $this->customise(array(
+ 'EditForm' => $form
+ ))->renderWith($this->getViewer('show'));
}
}
@@ -358,8 +362,8 @@ public function getitem() {
if($record && !$record->canView()) return Security::permissionFailure($this);
}
- $form = $this->EditForm();
- if ($form) return $form->formHtmlContent();
+ $form = $this->getEditForm();
+ if($form) return $form->formHtmlContent();
else return "";
}
public function getLastFormIn($html) {
@@ -815,21 +819,47 @@ public function deleteitems() {
return FormResponse::respond();
}
-
- public function EditForm() {
- // Include JavaScript to ensure HtmlEditorField works.
- HtmlEditorField::include_js();
-
- if ($this->currentPageID() != 0) {
- $record = $this->currentPage();
- if(!$record) return false;
- if($record && !$record->canView()) return Security::permissionFailure($this);
- }
- if ($this->hasMethod('getEditForm')) {
- return $this->getEditForm($this->currentPageID());
- }
-
- return false;
+
+ /**
+ * Gets the edit form of a specific record. Will usually construct itself
+ * from {@link DataObject->getCMSFields()} for the specific managed subclass
+ * defined in {@link LeftAndMain::$tree_class}.
+ *
+ * @param int $id ID of a record for {@link LeftAndMain::$tree_class} (Optional)
+ * @return Form Should return a form regardless wether a record has been found.
+ * Form might be readonly if the current user doesn't have the permission to edit
+ * the record.
+ */
+ function getEditForm($id = null) {
+ die('getEditForm(): Not implemented');
+ }
+
+ /**
+ * Returns a placeholder form, used by {@link getEditForm()} if no record is selected.
+ * Our javascript logic always requires a form to be present in the CMS interface.
+ *
+ * @return Form
+ */
+ function EmptyForm() {
+ return new Form(
+ $this,
+ "EditForm",
+ new FieldSet(
+ new HeaderField(
+ 'WelcomeHeader',
+ $this->getApplicationName()
+ ),
+ new LiteralField(
+ 'WelcomeText',
+ sprintf('<p>%s %s. %s</p>',
+ _t('LeftAndMain_right.ss.WELCOMETO','Welcome to'),
+ $this->getApplicationName(),
+ _t('CHOOSEPAGE','Please choose an item from the left.')
+ )
+ )
+ ),
+ new FieldSet()
+ );
}
public function myprofile() {
View
@@ -48,13 +48,15 @@ public function init() {
Requirements::javascript(THIRDPARTY_DIR . "/greybox/greybox.js");
}
- public function getEditForm($id) {
+ public function getEditForm($id = null) {
$record = null;
if($id && $id != 'root') {
$record = DataObject::get_by_id($this->stat('tree_class'), $id);
}
+ if($record && !$record->canView()) return Security::permissionFailure($this);
+
if($record) {
$fields = $record->getCMSFields();
@@ -71,12 +73,7 @@ public function getEditForm($id) {
$form->setFields($readonlyFields);
}
} else {
- $form = new Form(
- $this,
- "EditForm",
- new FieldSet(),
- new FieldSet()
- );
+ $form = $this->EmptyForm();
}
return $form;
@@ -35,11 +35,6 @@
// Can't bind this through jQuery
window.onbeforeunload = function(e) {return self._checkChangeTracker(false);};
- // set default placeholder if form has no children
- this.setPlaceholderHtml(jQuery('.ss-cmsForm-welcomeMessage').html());
- jQuery('.ss-cmsForm-welcomeMessage').remove();
- if(!self.find('*').length) self.removeForm();
-
$._super();
},
@@ -1,11 +1,3 @@
-<div class='ss-cmsForm-welcomeMessage'>
- <h1>$ApplicationName</h1>
- <p>
- <% _t('WELCOMETO','Welcome to') %> $ApplicationName!
- <% _t('CHOOSEPAGE','Please choose an item from the left.') %>
- </p>
-</div>
-
$EditForm
<div class="notice-wrap"></div>

0 comments on commit dc4375a

Please sign in to comment.