From c38a898de3797685bc68d97d2327bff97868f5e9 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 11 Feb 2010 01:02:34 +0000 Subject: [PATCH] ENHANCEMENT Allowing custom 'root forms' when id values '0' or 'root' are passed from the tree selection. (rewritten from r98710) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@98735 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/LeftAndMain.php | 34 +++++++++++++++++++++++++++++++++- code/SecurityAdmin.php | 22 +++++++--------------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index 77bd75cc..ef74f2fd 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -509,7 +509,7 @@ class LeftAndMain extends Controller { // Wrap the root if needs be. if(!$rootID) { - $rootLink = $this->Link() . '0'; + $rootLink = $this->Link('show') . '/root'; // This lets us override the tree title with an extension if($this->hasMethod('getCMSTreeTitle') && $customTreeTitle = $this->getCMSTreeTitle()) { @@ -939,10 +939,42 @@ JS; } } + FormResponse::add($script); return FormResponse::respond(); } + + /** + * 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() { + $form = new Form( + $this, + "EditForm", + new FieldSet( + new HeaderField( + 'WelcomeHeader', + $this->getApplicationName() + ), + new LiteralField( + 'WelcomeText', + sprintf('

%s %s. %s

', + _t('LeftAndMain_right.ss.WELCOMETO','Welcome to'), + $this->getApplicationName(), + _t('CHOOSEPAGE','Please choose an item from the left.') + ) + ) + ), + new FieldSet() + ); + $form->unsetValidator(); + + return $form; + } public function EditForm() { // Include JavaScript to ensure HtmlEditorField works. diff --git a/code/SecurityAdmin.php b/code/SecurityAdmin.php index 784caf75..d97656e9 100644 --- a/code/SecurityAdmin.php +++ b/code/SecurityAdmin.php @@ -59,7 +59,12 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider { public function getEditForm($id) { $record = null; - if (($id == 'root' || $id == 0) && $this->hasMethod('getRootForm')) return $this->getRootForm($this, 'EditForm'); + if (($id == 'root' || $id == 0)) { + $form = $this->RootForm(); + $this->extend('augmentRootForm', $form); + + return $form; + } if($id && $id != 'root') { $record = DataObject::get_by_id($this->stat('tree_class'), $id); @@ -77,20 +82,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider { $form = new Form($this, "EditForm", $fields, $actions); $form->loadDataFrom($record); - $fields = $form->Fields(); - - if($fields->hasTabSet()) { - $fields->findOrMakeTab('Root.Import',_t('Group.IMPORTTABTITLE', 'Import')); - $fields->addFieldToTab('Root.Import', - new LiteralField( - 'MemberImportFormIframe', - sprintf( - '', - $this->Link('memberimport') - ) - ) - ); - } + if(!$record->canEdit()) { $readonlyFields = $form->Fields()->makeReadonly();