Отключить расширитель текстовой области в Drupal?
Подобно форме публикации вопросов в SO, Drupal добавляет перетаскиваемый экспандер в конец текстовых областей, созданных через форму API. Как я могу отключить это хорошим способом?
5 ответов
Перетаскиваемый расширитель добавляется с помощью поведения, определенного в 'misc/textearea.js'. Из этого вы можете видеть, что это относится к текстовым областям, имеющим класс "изменяемого размера". Вы можете запретить вывод этого класса, если вы установите свойство '#resizable' в определении FAPI для textareas на FALSE (по умолчанию это TRUE, если явно не установлено).
Так что для ваших собственных форм вы можете просто объявить текстовые поля соответственно. Для других форм вам нужно настроить их через hook_form_alter()
,
Новый модуль под названием Disable Resizable Textarea был выпущен сейчас.
Это простой модуль, который добавляет возможность переопределять стандартное свойство #resizable полей textarea. По умолчанию все текстовые области могут быть изменены. Этот модуль позволяет отключить эту функцию на каждом поле.
Это очень легко настроить. Просто отредактируйте нужное поле, и вы увидите опцию "Отключить свойство #resizable этого текстового поля". Вы также можете отключить изменение размера из его сводки, если поле имеет тип "Длинный текст со сводкой".
Самое простое, было бы удалить файл /misc/textarea.js
,
Сложнее, но, вероятно, лучше, исправить это либо в вашей теме, либо в крошечном модуле.
В вашей теме у вас снова есть два варианта:
- используйте препроцесс для удаления textarea.js из списка файлов javascript.
- использовать переопределение темы (
yourtheme_textarea
) удалить классresizable-textarea
из отрендеренного HTML. Некоторая информация об этом на форумах
Опция в модуле, будет запускать 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 и немного изменены.
В вашей теме это очень просто, но требует тему, которую вы можете переопределить. Модуль хуже по производительности и намного сложнее. Тем не менее, это будет работать на любую тему.
Есть способы, как удалить изменяемый размер текстовой области в Drupal (7).
1-е место это простое врезалось в вашу тему 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.