FEATURE: Allow different user groups to have different HtmlEditorConfigs

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@84085 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew O'Neil 2009-08-10 03:53:36 +00:00 committed by Sam Minnee
parent 047d17d512
commit 38846653a2
3 changed files with 41 additions and 1 deletions

View File

@ -41,10 +41,27 @@ class HtmlEditorConfig {
return self::get($identifier);
}
/**
* Get the available configurations as a map of friendly_name to
* configuration name.
* @return array
*/
static function get_available_configs_map() {
$configs = array();
foreach(self::$configs as $identifier => $config) {
$configs[$identifier] = $config->getOption('friendly_name');
}
return $configs;
}
/**
* Holder for all TinyMCE settings _except_ plugins and buttons
*/
protected $settings = array(
'friendly_name' => '(Please set a friendly name for this config)',
'priority' => 0,
'mode' => "specific_textareas",
'editor_selector' => "htmleditor",
'width' => "100%",

View File

@ -14,6 +14,7 @@ class Group extends DataObject {
"Locked" => "Boolean",
"Sort" => "Int",
"IPRestrictions" => "Text",
"HtmlEditorConfig" => "Varchar"
);
static $has_one = array(
@ -63,6 +64,7 @@ class Group extends DataObject {
) .
"</p>"
),
new DropdownField('HtmlEditorConfig', 'HTML Editor Configuration', HtmlEditorConfig::get_available_configs_map()),
new TableField(
"Permissions",
"Permission",

View File

@ -982,6 +982,27 @@ class Member extends DataObject {
user_error('Member::isInGroup() is deprecated. Please use inGroup() instead.', E_USER_NOTICE);
return $this->inGroup($groupID);
}
/**
* Get the HtmlEditorConfig for this user to be used in the CMS.
* This is set by the group.
* @return string
*/
function getHtmlEditorConfigForCMS() {
$currentName = '';
$currentPriority = 0;
foreach($this->Groups() as $group) {
$configName = $group->HtmlEditorConfig;
$config = HtmlEditorConfig::get($group->HtmlEditorConfig);
if($config && $config->getOption('priority') > $currentPriority) {
$currentName = $configName;
}
}
// If can't find a suitable editor, just default to cms
return $currentName ? $currentName : 'cms';
}
}
@ -1452,4 +1473,4 @@ class Member_Validator extends RequiredFields {
// Initialize the static DB variables to add the supported encryption
// algorithms to the PasswordEncryption Enum field
Member::init_db_fields();
?>
?>