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 6994c6662..beabea9c4 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 e006d309d..bf625197a 100644 --- a/security/Member.php +++ b/security/Member.php @@ -1026,6 +1026,27 @@ class Member extends DataObject { } } } + + /** + * 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'; + } } /**