2010-04-21 73 views
5

是否可以在texarea 爲Drupal站點配置表單(system_settings_form)使用WYSIWYG編輯器。所見即所得編輯器在texarea Drupal配置表格

這是怎樣的配置現在編碼...

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

回答

0

所見即所得或CKEditor的模塊應該能夠做到這一點。

+0

是的,應該的。只是想知道如何實現這一點。 – bert 2010-04-22 10:18:41

+0

我個人喜歡CKEditor;您可以下載並安裝該模塊,然後從官方網站下載CKEditor庫並將其放置在正確的文件夾中。說明會引導您完成此操作。 – Nicholai 2010-04-26 18:03:27

1

我一直在尋找這個問題的約6小時,終於讓我找到了原因,爲您的自定義textarea的領域,你必須加入這一行,使用默認的輸入格式(全HTML):

$形式[ 'format'] = filter_form();

如果使用這種形式的元素內部字段集必須包括這個字段集要小心:

$形式[「捐贈的指令」] [「格式」] = filter_form();

我希望這將有助於你

0

我發現這個問題類似於:

Drupal 6: Implement Wysiwyg on Custom Module Form

答案之一有指向此頁面drupal.org:

http://drupal.org/node/358316

其中提供了相當詳細的「格式」數組鍵和filter_form()的例子,也desc如果你的表單有多個textareas,它會如何使用它。

給予有不適的Drupal 7

我遇到類似的情況,我倒是下載和安裝,並安裝CKEditor的和編輯內容節點時,它顯示出來,但並沒有顯示這種方法在我的模塊配置表單上的textarea。

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

這真的是一個更好的答案,因爲所見即所得模塊不會在沒有這個代碼的情況下做一件事。 – 2012-08-03 14:42:36