禁用Drupal';文本区域扩展器?
与SO上的问题发布表单类似,Drupal在通过表单api创建的文本区域底部添加了一个可拖动的扩展程序。如何以一种好的方式禁用它?通过“misc/textearea.js”中定义的行为添加可拖动的扩展器。从中可以看出,它适用于具有“可调整大小”类的文本区域。如果设置为FALSE,则可以阻止此类的输出(如果未显式设置,则默认为TRUE)禁用Drupal';文本区域扩展器?,drupal,form-api,Drupal,Form Api,与SO上的问题发布表单类似,Drupal在通过表单api创建的文本区域底部添加了一个可拖动的扩展程序。如何以一种好的方式禁用它?通过“misc/textearea.js”中定义的行为添加可拖动的扩展器。从中可以看出,它适用于具有“可调整大小”类的文本区域。如果设置为FALSE,则可以阻止此类的输出(如果未显式设置,则默认为TRUE) 因此,对于您自己的表单,您可以相应地声明textareas。对于其他表单,您需要通过hook\u form\u alter()调整它们。最简单的方法是删除文件/mi
因此,对于您自己的表单,您可以相应地声明textareas。对于其他表单,您需要通过
hook\u form\u alter()
调整它们。最简单的方法是删除文件/misc/textarea.js
更难但可能更好的方法是在主题或一个小模块中解决这个问题
在主题中,您还有两个选项:
- 使用预处理从javascript文件列表中删除textarea.js李>
- 使用主题覆盖(
)从呈现的HTML中删除类yourtheme\u textarea
。这方面的一些信息可调整大小的textarea
hook\u form\u 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模块,稍作修改
在您的主题中,它非常简单,但需要一个可以覆盖的主题。该模块在性能方面更差,而且更复杂。但是,它可以用于任何主题。现在发布了一个名为was的新模块
body textarea {
resize: none;
}
这是一个简单的模块,添加了覆盖textarea字段的默认可调整大小属性的功能。默认情况下,所有文本区域都可以调整大小。此模块允许您在每个字段上禁用此功能
设置起来很容易。只需编辑所需字段,您将看到“禁用此文本区域的可调整大小属性”选项。如果字段类型为“带摘要的长文本”,您还可以从其摘要中禁用可调整大小的功能。在Drupal(7)中有多种方法可以删除可调整大小的文本区域
1th将这个简单的片段放入主题template.php
。别忘了将主题名重命名为你的主题名
/**
* 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;
}
/**
*重写主题('textarea')。
*反对misc/textarea.js,赞成使用“resize”CSS3属性。
*/
函数THEMENAME_textarea($variables){
$element=$variables['element'];
元素集属性($element,array('id','name','cols','rows');
_form_set_类($element,array('form-textarea'));
$wrapper\u attributes=数组(
'class'=>array('form-textarea-wrapper'),
);
$output='';
$output.=''.check_plain($element['#value'])。';
$output.='';
返回$output;
}
2nd另一种方法是使用另一个名为的模块
.你的意思是如何做到这一点而不改变Drupal^Rant附带的任何文件-为什么Drupal添加了一些我们需要花费精力才能禁用的冗余内容,然而,我需要安装一个模块来实现一些重要的功能,比如简单地向菜单项添加类?你永远不应该从/misc/中删除文件:除了站点目录之外,所有的东西都应该是原始的。钩形改变是移除它的正确方法。我不同意。尽管如此,这是一条很好的经验法则,有很多理由不去触碰Drupal核心,它/是/而是一条教条。通常,额外代码、模块维护和开销的开销不值得在适当的RCS中管理一个简单的核心补丁。您可以停止在主题层加载javascript文件,这比直接删除它们要好。啊,谢谢!我查看了表单api好几次,但都没有看到。我在找可扩展的!