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
This commit is contained in:
Ingo Schommer 2010-02-22 09:38:15 +00:00
parent 9c00cac768
commit 09de9f7834
2 changed files with 21 additions and 6 deletions

View File

@ -65,7 +65,6 @@ class Group extends DataObject {
) . ) .
"</p>" "</p>"
), ),
new DropdownField('HtmlEditorConfig', 'HTML Editor Configuration', HtmlEditorConfig::get_available_configs_map()),
new PermissionCheckboxSetField( new PermissionCheckboxSetField(
'Permissions', 'Permissions',
singleton('Permission')->i18n_plural_name(), 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')) { if(!Permission::check('EDIT_PERMISSIONS')) {
$fields->removeFieldFromTab('Root', 'Permissions'); $fields->removeFieldFromTab('Root', 'Permissions');

View File

@ -1164,7 +1164,9 @@ class Member extends DataObject {
/** /**
* Get the HtmlEditorConfig for this user to be used in the CMS. * 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 * @return string
*/ */
function getHtmlEditorConfigForCMS() { function getHtmlEditorConfigForCMS() {
@ -1173,9 +1175,11 @@ class Member extends DataObject {
foreach($this->Groups() as $group) { foreach($this->Groups() as $group) {
$configName = $group->HtmlEditorConfig; $configName = $group->HtmlEditorConfig;
$config = HtmlEditorConfig::get($group->HtmlEditorConfig); if($configName) {
if($config && $config->getOption('priority') > $currentPriority) { $config = HtmlEditorConfig::get($group->HtmlEditorConfig);
$currentName = $configName; if($config && $config->getOption('priority') > $currentPriority) {
$currentName = $configName;
}
} }
} }