With a custom Drupal form, how can you attach WYSIWYG functionality to a textarea with the WYSIWYG module?
review this indication to Drupal 7 (with a little indication to drupal 6) http://drupal.org/node/1031160. specifically is about how to display an editor inside textarea in drupal 7, so I guess that could be useful to start (seems that the last comment have a tested way).
may be could be an alternative to do this instead/with WYSIWYG.
The wysiwyg module is tied to the input format system.
'#type' => 'text_format' when defining your text area.
You should use type = 'text_format' instead of text area. and format = 'editor_format'. The code will look like this.
$form['description'] = array( '#type' => 'text_format', '#title' => t('Description'), '#format' => 'full_html' //the format used for editor. );
Here is mine:
$form['my_module_my_form_my_field'] = array( '#type' => 'text_format', '#title' => t('Awesome title'), '#format' => isset($edit['format']) ? $edit['format'] : NULL, '#base_type' => 'textarea', '#default_value' => variable_get('my_module_my_form_my_field', '')['value'], '#description' => t("Awesome description."), '#required' => FALSE, '#maxlength' => 500, );
I had to add the
['value'] to the
#default_value cause it wasn't being loaded after saved.
The WYSIWYG module is only a way to use one of the many wysiwyg editors out there. Once you install the wysiwyg module (http://drupal.org/project/wysiwyg), go to the configuration for the module (admin/config/content/wysiwyg). There will be installation instructions for many Wysiwyg editors available. For example, for FCKeditor, it says the following:
Extract the archive and copy its contents into a new folder in the following location: sites/all/libraries/fckeditor
So the actual library can be found at: sites/all/libraries/fckeditor/fckeditor.js
So, download the editor, extract the archive to the given directory. Once you do this (assuming you've done it correctly), you will be able to change the editor for given input formats on the Wysiwyg config screen. You will then need to assign different operations for each type (filtered HTML, full HTML, etc.). Click "Edit" under operations within the admin/config/content/wysiwyg in the row for whichever input format you're interested in. From here, check which buttons you want.
It doesn't seem it is possible with Wysiwyg version 7.x-2, but the form builder for the profile settings uses the following array:
$profile['settings'] += array( 'default' => TRUE, 'user_choose' => FALSE, 'show_toggle' => TRUE, 'theme' => 'advanced', 'language' => 'en', 'access' => 1, 'access_pages' => "node/*\nuser/*\ncomment/*", 'buttons' => array(), 'toolbar_loc' => 'top', 'toolbar_align' => 'left', // ... );
The "access_pages" array index would allow to set for which pages the editor is shown, but the module doesn't provide any form field to change that code, nor does any function uses that value.
It could be that value was used in previous versions, and the code to handle it is still being ported, or that option is being introduced within the next versions of the module.