在textarea中的WYSIWYG编辑器,用于Drupal配置表单

时间:2010-04-21 15:41:49

标签: drupal configuration forms textarea wysiwyg

是否可以在textarea中使用WYSIWYG编辑器 对于Drupal站点配置表单(system_settings_form)。

这就是现在编码配置的方式......

$form['my_module_text_bottom'] = array(
    '#type' => 'textarea',
    '#title' => t('Some text'),
    '#default_value' => variable_get('my_module_text_bottom', 'This is configurable text found in the module configuration.'),
    '#size' => 1024,
    '#maxlength' => 1024,
    '#description' => t("Some text."),
    '#required' => TRUE,
  );
  return system_settings_form($form);

4 个答案:

答案 0 :(得分:4)

此处为for Drupal 7Drupal 6

对于D7:

<?php
  // Retrieve the default values for 'value' and 'format', if not readily
  // available through other means:
  $defaults = array(
    'value' => '',
    'format' => filter_default_format(),
  );
  $my_richtext_field = variable_get('my_richtext_field', $defaults);

  // Just construct a regular #type 'text_format' form element:
  $form['my_richtext_field'] = array(
    '#type' => 'text_format',
    '#title' => t('My richtext field'),
    '#default_value' => $my_richtext_field['value'],
    '#format' => $my_richtext_field['format'],
  );
?>

对于D6:

<?php
  // Your saved or new data is supposed to have a value and a format. Just like
  // $node has a $node->body and $node->format. May also come from a
  // variable_get('mymodule_admin_setting', array('value' => '', 'format' => NULL));
  $mydata = mymodule_data_load();

  $form['myfield']['mytextarea'] = array(
    '#type' => 'textarea',
    '#title' => t('My textarea'),
    '#default_value' => $mydata->value,
  );
  $form['myfield']['format'] = filter_form($mydata->format);
?>

答案 1 :(得分:1)

我一直在搜索这个问题大约6个小时,最后我找到了原因,对于你的自定义textarea字段,你必须添加这一行,使用默认的输入格式(完整的HTML):

$ form ['format'] = filter_form();

如果在fieldset中使用此表单元素,请务必小心,必须包含此字段集:

$ form ['donation-instructions'] ['format'] = filter_form();

我希望这会对你有所帮助

答案 2 :(得分:0)

WYSIWYG或CKEditor模块应该能够做到这一点。

答案 3 :(得分:0)

我发现这个问题类似于:

Drupal 6: Implement Wysiwyg on Custom Module Form

其中一个答案指向了这个drupal.org页面:

http://drupal.org/node/358316

提供了“format”数组键和filter_form()的相当详细的示例,还描述了如果表单具有多个textareas时如何使用它。

那里给出的方法不适用于Drupal 7.

我遇到了类似的情况,我下载并安装并安装了CKEditor,它在编辑内容节点时显示,但在我的模块的配置表单上没有显示textarea。