From 09de9f7834444e2817384633d28a604454867905 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 22 Feb 2010 09:38:15 +0000 Subject: [PATCH] ENHANCEMENT Only show 'HTML Editor Config' dropdown in Group->getCMSFields() if more than one option exists BUGFIX Fixed bogus HTMLEditorConfig instance when get() is called without a valid identifier (due to NULL database columns) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@99599 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- security/Group.php | 15 +++++++++++++-- security/Member.php | 12 ++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/security/Group.php b/security/Group.php index 3921e0a76..055ce1f77 100644 --- a/security/Group.php +++ b/security/Group.php @@ -65,7 +65,6 @@ class Group extends DataObject { ) . "

" ), - new DropdownField('HtmlEditorConfig', 'HTML Editor Configuration', HtmlEditorConfig::get_available_configs_map()), new PermissionCheckboxSetField( 'Permissions', singleton('Permission')->i18n_plural_name(), @@ -90,7 +89,19 @@ class Group extends DataObject { ) ); - + // Only add a dropdown for HTML editor configurations if more than one is available. + // Otherwise Member->getHtmlEditorConfigForCMS() will default to the 'cms' configuration. + $editorConfigMap = HtmlEditorConfig::get_available_configs_map(); + if(count($editorConfigMap) > 1) { + $fields->addFieldToTab('Root.Permissions', + new DropdownField( + 'HtmlEditorConfig', + 'HTML Editor Configuration', + $editorConfigMap + ), + 'Permissions' + ); + } if(!Permission::check('EDIT_PERMISSIONS')) { $fields->removeFieldFromTab('Root', 'Permissions'); diff --git a/security/Member.php b/security/Member.php index 6980e2fdb..4fcb3c78e 100755 --- a/security/Member.php +++ b/security/Member.php @@ -1164,7 +1164,9 @@ class Member extends DataObject { /** * Get the HtmlEditorConfig for this user to be used in the CMS. - * This is set by the group. + * This is set by the group. If multiple configurations are set, + * the one with the highest priority wins. + * * @return string */ function getHtmlEditorConfigForCMS() { @@ -1173,9 +1175,11 @@ class Member extends DataObject { foreach($this->Groups() as $group) { $configName = $group->HtmlEditorConfig; - $config = HtmlEditorConfig::get($group->HtmlEditorConfig); - if($config && $config->getOption('priority') > $currentPriority) { - $currentName = $configName; + if($configName) { + $config = HtmlEditorConfig::get($group->HtmlEditorConfig); + if($config && $config->getOption('priority') > $currentPriority) { + $currentName = $configName; + } } }