diff --git a/forms/HtmlEditorConfig.php b/forms/HtmlEditorConfig.php index 94dd40388..b0d4cb4d5 100644 --- a/forms/HtmlEditorConfig.php +++ b/forms/HtmlEditorConfig.php @@ -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%", diff --git a/security/Group.php b/security/Group.php index 5bac6dfbf..b3db34837 100644 --- a/security/Group.php +++ b/security/Group.php @@ -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 { ) . "

" ), + new DropdownField('HtmlEditorConfig', 'HTML Editor Configuration', HtmlEditorConfig::get_available_configs_map()), new TableField( "Permissions", "Permission", diff --git a/security/Member.php b/security/Member.php index d8636979e..4c7f79844 100644 --- a/security/Member.php +++ b/security/Member.php @@ -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(); -?> \ No newline at end of file +?>