Currently we give a particular textarea control its settings in two steps: (1) read in the current user's default profile's settings (the conf array) in tinymce_config() and then (2) pass it through a theme function, theme_tinymce_theme(), which is coded to make adjustments based mainly on the name of the control, e.g., assign the 'simple' theme to specific fields.
Designed before we had access to the forms api, this system has many limitations, e.g., to change a particular field we need to hard-code changes into the tinymce module (or into a theme override, really a misuse of the theme system).
In http://drupal.org/node/118747 I suggested (as part of a rework of the jquery code) moving to a module hook instead of the theme override. But on seciond thought, no. What we really need to do is move to a standard forms api handling, like we do with other behaviours, e.g., autocomplete.
That is, we should assign a property to textareas that triggers this behaviour.
While we're at it, we should consider generalizing this property, so it can be for any WYSIWYG behaviour rather than just tinymce. Rather than calling it, e.g., #tinymce, I'd propose #wysiwyg.
Besides the boolean of whether to attach the behaviour, the other main issue is what style/theme to use. For this, we usually have a 'simple' and 'advanced'. So, again to make this library-neutral, we could call this #wysiwyg_style. Here's how we'd declare it:
/**
* Implementation of hook_elements().
*/
function tinymce_elements() {
$type = array();
if (user_access('access tinymce')) {
$type['textarea'] = array('#process' => array('tinymce_process_textarea' => array()), '#wysiwyg' => TRUE, '#wysiwyg_style' => 'advanced');
}
return $type;
}
Then in tinymce_process_textarea() we would test for these properties and set tinymce to trigger accordingly.
Comments
Comment #1
nedjoThis is how we should probably be doing our inits:
http://wiki.moxiecode.com/examples/tinymce/installation_example_10.php
In
tinymce_process_textarea()we add classes to the textareas. Then we trigger one init per configuration, not using the elements paramater but instead the editor_selector one. We save calling init once per textarea, and also save the need to pass data to the client on which textareas to apply to. Our css classes could be, e.g., tinymce-simple, tinymce-advanced.Comment #2
kreynen commentedThe more we follow the implementation recommendations made by Moxiecode, the more we benefit from the TinyMCE work going on outside of Drupal.
Comment #3
nedjoI've incorporated this change in http://drupal.org/node/118747.
I tried implementing the editor_selector approach, but it wasn't feasible, due to internal inconsistencies in how tinyMCE determines ids for elements. [Semi-technical explanation: When we use editor_selector, tinyMCE uses the name rather than the id attribute to form the id, which is problematic for various reasons (nested elements have name attributes that don't translate well to strings, tinyMCE in certain other cases defaults to id over name, etc.).]
By using the elements property, as I've done in http://drupal.org/node/118747.
Comment #4
nedjoI've submitted a patch to fckeditor module to use this same Forms API appproach, http://drupal.org/node/122008.
Comment #5
mupsi