SO の質問投稿フォームと同様に、Drupal はフォーム API で作成されたテキストエリアの下部にドラッグ可能なエキスパンダーを追加します。これをうまく無効にするにはどうすればよいですか?
5 に答える
ドラッグ可能なエキスパンダーは、「misc/textearea.js」で定義された動作を介して追加されます。そこから、「サイズ変更可能」クラスを持つテキストエリアに適用されることがわかります。textareas FAPI 定義の '#resizable' プロパティを FALSE に設定すると、このクラスの出力を防ぐことができます (明示的に設定されていない場合、デフォルトで TRUE になります)。
したがって、独自のフォームの場合は、それに応じてテキストエリアを宣言するだけです。他のフォームについては、 で調整する必要がありますhook_form_alter()
。
body textarea {
resize: none;
}
最も簡単な方法は、ファイルを削除することです/misc/textarea.js
。
難しいが、おそらくより良い方法は、テーマまたは小さなモジュールでこれを修正することです。
テーマには、2 つのオプションがあります。
- 前処理を使用して、javascript ファイルのリストから textarea.js を削除します。
- テーマ オーバーライド ( ) を使用して、レンダリングされた HTML から
yourtheme_textarea
クラスを削除します。フォーラムでのresizable-textarea
それに関するいくつかの情報
モジュールのオプションは、 a を実行し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 モジュールのもので、わずかに変更されています。
In your theme は非常に単純ですが、オーバーライドできるテーマが必要です。このモジュールは、パフォーマンスの面で劣っており、はるかに複雑です。ただし、どのテーマでも機能します。