2010-07-25 35 views
2

與SO上的問題發佈表單類似,Drupal在通過表單api創建的textareas底部添加了一個可拖動的擴展器。我怎樣才能以很好的方式禁用它?禁用Drupal的textarea擴展器?

+0

你的意思是如何做到這一點,而不用修改Drupal附帶的任何文件^ – kiamlaluno 2010-07-25 13:28:58

+0

是的 - 正是如此。 – Finbarr 2010-07-25 13:35:20

+0

Rant - 爲什麼Drupal添加了一些冗餘的東西,我們需要花費精力去禁用,但是我需要安裝一個重要的功能模塊,比如簡單地向菜單項添加類。 – dayuloli 2015-02-11 09:42:22

回答

8

可拖動的擴展器通過'misc/textearea.js'中定義的行爲來添加。從這裏你可以看出,它適用於textareas類'可調整大小'。如果將the '#resizable' property on a textareas FAPI definition設置爲FALSE(如果未明確設置,則默認爲TRUE),則可以防止此類的輸出。

因此,對於您自己的表單,您可以相應地聲明textareas。對於其他表格,您需要通過hook_form_alter()進行調整。

+0

啊,謝謝!我多次查看了表單api,但看不到這一點。我正在尋找'#可擴展的! – Finbarr 2010-07-25 23:38:07

0

最簡單的,將刪除文件/misc/textarea.js

更難但可能更好的方法是解決這個在你的主題,或在一個小模塊。

在你的主題,你必須再次兩種選擇:

  • 使用預處理從的JavaScript文件列表中刪除textarea.js。
  • 使用主題覆蓋(yourtheme_textarea)從呈現的HTML中移除類resizable-textarea。上in the forums

一個模塊中的選項的一些信息,將運行一個hook_form_alter()抓住任何形式和運行槽的處理器:

/** 
* Implementation of hook_form_alter(). 
* 
* Before Drupal 7, there is no way to easily identify form fields that are 
* input format enabled. As a workaround, we assign a form #after_build 
* processing callback that is executed on all forms after they have been 
* completely built, so form elements are in their effective order 
* and position already. 
* 
* @see wysiwyg_process_form() 
*/ /** 
* Implementation of hook_form_alter(). 
* 
* Before Drupal 7, there is no way to easily identify form fields that are 
* input format enabled. As a workaround, we assign a form #after_build 
* processing callback that is executed on all forms after they have been 
* completely built, so form elements are in their effective order 
* and position already. 
* 
* @see wysiwyg_process_form() 
*/ 
function wysiwyg_form_alter(&$form, &$form_state) { 
    $form['#after_build'][] = 'wysiwyg_process_form'; 
    // Teaser splitter is unconditionally removed and NOT supported. 
    if (isset($form['body_field'])) { 
    unset($form['body_field']['teaser_js']); 
    } 
} 

function wysiwyg_process_form(&$form) { 
    // Iterate over element children; resetting array keys to access last index. 
    if ($children = array_values(element_children($form))) { 
    foreach ($children as $index => $item) { 
     $element = &$form[$item]; 

     // filter_form() always uses the key 'format'. We need a type-agnostic 
     // match to prevent false positives. Also, there must have been at least 
     // one element on this level. 
     if (($item === 'format' || $item === 'signature_format') && $index > 0) { 
     // Make sure we either match a input format selector or input format 
     // guidelines (displayed if user has access to one input format only). 
     if ((isset($element['#type']) && $element['#type'] == 'fieldset') || isset($element['format']['guidelines'])) { 
      // The element before this element is the target form field. 
      $field = &$form[$children[$index - 1]]; 

      $extra_class = ''; 
      if (!empty($field['#resizable'])) { 
      $extra_class = ' wysiwyg-resizable-1'; 
      drupal_add_js('misc/textarea.js'); 
      } 

      // If we loaded at least one editor, then the 'none' editor will 
      // handle resizable textareas instead of core. 
      if (isset($loaded) && !empty($field['#resizable'])) { 
      $field['#resizable'] = FALSE; 
      } 
     } 
     // If this element is 'format', do not recurse further. 
     continue; 
     } 
     // Recurse into children. 
     wysiwyg_process_form($element); 
    } 
    } 
    return $form; 
} 

這些實例是從WYSIWYG模塊,和略改變。

在你的主題很簡單,但需要一個你可以覆蓋的主題。該模塊在性能上更差,而且更復雜。但是,它將適用於任何主題。

+0

你不應該從/ misc /中刪除文件:除了sites目錄以外的每件事都應該是原始的。 hook_form_alter是刪除它的正確方法。 – 2010-07-25 22:39:46

+0

我不同意。儘管如此,這是一個很好的經驗法則,並且有許多理由不要觸及Drupal Core,它只是一個教條。通常額外代碼的開銷,模塊維護和開銷不值得在適當的RCS中管理一個簡單的核心補丁。 – berkes 2010-07-26 07:33:40

+0

您可以停止在主題圖層中加載JavaScript文件,這比刪除它們更好。 – cam8001 2010-07-26 13:10:15

1
body textarea { 
    resize: none; 
} 
2

現在發佈一個名爲Disable Resizable Textarea的新模塊。

這是一個簡單的模塊,可以添加覆蓋textarea字段默認#resizable屬性的功能。默認情況下,所有textareas都可以調整大小。此模塊允許您在每個字段禁用此功能。

這很容易設置。只需編輯所需的字段,您將看到一個「禁用此文本區域的#resizable屬性」選項。如果該字段的類型爲「帶摘要的長文本」,則還可以禁用其摘要中的可調整大小。

0

有如何刪除Drupal(7)中可調整大小的textarea的方法。

1th把這個簡單的剪裁到你的主題template.php。不要忘記將THEMENAME重命名爲您的主題名稱。

/** 
* Override of theme('textarea'). 
* Deprecate misc/textarea.js in favor of using the 'resize' CSS3 property. 
*/ 

function THEMENAME_textarea($variables) { 
    $element = $variables ['element']; 
    element_set_attributes($element, array('id', 'name', 'cols', 'rows')); 
    _form_set_class($element, array('form-textarea')); 

    $wrapper_attributes = array(
    'class' => array('form-textarea-wrapper'), 
); 

    $output = '<div' . drupal_attributes($wrapper_attributes) . '>'; 
    $output .= '<textarea' . drupal_attributes($element ['#attributes']) . '>' . check_plain($element ['#value']) . '</textarea>'; 
    $output .= '</div>'; 
    return $output; 
} 

第二另一種方法是使用另一個模塊調用Disable resizable textarea

More info and source