texarea 中用于 Drupal 配置表单的所见即所得编辑器

发布于 2024-08-29 21:36:59 字数 527 浏览 4 评论 0 原文

是否可以在 texarea 中使用所见即所得编辑器 用于 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);

Is it possible to use a WYSIWYG editor in texarea
for Drupal site configuration form (system_settings_form).

This is how the configuration is coded now...

$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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

十雾 2024-09-05 21:36:59

这里是 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);
?>

Here it is for Drupal 7 and Drupal 6.

For 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'],
  );
?>

For 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);
?>
难以启齿的温柔 2024-09-05 21:36:59

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

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

请注意,如果您在字段集中使用此表单元素,则必须包含此字段集:

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

我希望这会帮助你

I kept searching for this issue for about 6 hours and finally i found the reason, for your custom textarea field you must add this line, to use the default input format (Full HTML):

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

be careful if you use this form element inside fieldset you must include this fieldset:

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

I hope this will help you

风启觞 2024-09-05 21:36:59

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

The WYSIWYG or CKEditor modules should be able to do this.

我最亲爱的 2024-09-05 21:36:59

我发现这个问题类似于:

Drupal 6: Implement Wysiwyg on Custom Module Form

那里的答案之一指向这个 drupal.org 页面:

http://drupal.org/node /358316

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

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

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

I found this question similar to:

Drupal 6: Implement Wysiwyg on Custom Module Form

One of the answers there pointed to this drupal.org page:

http://drupal.org/node/358316

which provides fairly detailed examples of the "format" array key and filter_form(), also describing how it's used if your form has multiple textareas.

The approach given there doesn't apply to Drupal 7.

I ran into a similar situation where I'd downloaded and installed and installed CKEditor and it displayed when editing content nodes, but didn't display for the textarea on a configuration form for my module.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文