禁用 Drupal 的文本区域扩展器?

发布于 2024-09-10 23:47:19 字数 79 浏览 7 评论 0原文

与 SO 上的问题发布表单类似,Drupal 在通过表单 api 创建的文本区域的底部添加了一个可拖动的扩展器。我怎样才能以一种好的方式禁用它?

Similar to the question posting form on SO, Drupal adds a draggable expander to the bottom of textareas created through the form api. How can I disable this in a nice manner?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

黯然 2024-09-17 23:47:19

可拖动扩展器是通过“misc/texteara.js”中定义的行为添加的。从这里您可以看到它适用于具有“可调整大小”类的文本区域。如果设置 ,则可以阻止此类的输出将 textareas FAPI 定义上的“#ressized”属性设置为 FALSE(如果未显式设置,则默认为 TRUE)。

因此,对于您自己的表单,您只需相应地声明文本区域即可。对于其他表单,您需要通过 hook_form_alter() 进行调整。

The draggable expander gets added via the behavior defined in 'misc/textearea.js'. From that you can see that it applies to textareas having a class 'resizable'. You can prevent the output of this class if you set the '#resizable' property on a textareas FAPI definition to FALSE (it defaults to TRUE if not explicitly set).

So for your own forms, you can just declare the textareas accordingly. For other forms, youD need to adjust them via hook_form_alter().

挽心 2024-09-17 23:47:19

一个名为禁用可调整大小的文本区域的新模块现已发布。

这是一个简单的模块,添加了覆盖文本区域字段的默认 #ressized 属性的功能。默认情况下,所有文本区域的大小都是可调整的。此模块允许您在每个字段上禁用此功能。

设置非常简单。只需编辑所需的字段,您就会看到“禁用此文本区域的 #ressized 属性”选项。如果字段的类型为“带摘要的长文本”,您还可以从其摘要中禁用可调整大小。

A new module called Disable Resizable Textarea was release now.

This is a simple module that add ability to override the default #resizable property of textarea fields. By default, all textareas are resizable. This module allows you to disable this feature on each field.

It is very easy to set up. Just edit the desired field and you will see an "Disable #resizable property of this textarea" option. You can also disable resizable from its summary, if the field is of type "Long text with summary".

夜深人未静 2024-09-17 23:47:19
body textarea {
  resize: none;
}
body textarea {
  resize: none;
}
祁梦 2024-09-17 23:47:19

最简单的方法是删除文件 /misc/textarea.js

更难但可能更好的方法是在您的主题或小模块中修复此问题。

在您的主题中,您再次有两个选择:

  • 使用预处理从 javascript 文件列表中删除 textarea.js。
  • 使用主题覆盖 (yourtheme_textarea) 从呈现的 HTML 中删除 ressized-textarea 类。 论坛中的一些信息

模块中的选项是运行 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 模块,并稍作修改。

您的主题非常简单,但需要一个可以覆盖的主题。该模块在性能方面更差,而且更复杂。但是,它适用于任何主题。

The simplest, would be to remove the file /misc/textarea.js.

The harder, but probably nicer way is to fix this in either your theme, or in a tiny module.

In your theme, you have two options again:

  • use a preprocess to remove the textarea.js from the list of javascript files.
  • use a theme override (yourtheme_textarea) to remove the class resizable-textarea from the rendered HTML. Some information on that in the forums

The option in a module, would be to run a hook_form_alter() to grab any form and run that trough a processor:

/**
 * 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;
}

These examples are from WYSIWYG module, and slightly altered.

In your theme is far simple, but requires a theme that you can override. The module is both performance-wise worse, and a lot more complex. However, it will work on any theme.

伪装你 2024-09-17 23:47:19

有多种方法可以在 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;
}

第二种另一种方法是使用另一个名为禁用可调整大小的模块文本区域

更多信息和来源

There are to ways how to remove resizable textarea in Drupal (7).

1th Place this simple snipped into your theme template.php. Don't forget to rename THEMENAME to your theme name.

 /**
 * 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;
}

2nd Other way is to use another module called Disable resizable textarea.

More info and source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文