With a custom Drupal form, how can you attach WYSIWYG functionality to a textarea with the WYSIWYG module?

  • I found the solution submitted by moon.watcher and Dylan Tack works perfectly. – user5994 Mar 5 '12 at 23:55

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.

| improve this answer | |

The wysiwyg module is tied to the input format system.

Use '#type' => 'text_format' when defining your text area.

| improve this answer | |

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.
| improve this answer | |
  • This is the correct option. But i can't get safe_value in form. – Guru Oct 29 '15 at 13:18

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.

7x Form API Reference

| improve this answer | |
  • 1
    Wow indeed, the variable_get('foo', '')['value'] suffix is really necessary. – leymannx May 22 '18 at 11:58

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.

| improve this answer | |

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.