简体   繁体   English

用于varchar字段的Drupal文本模块多行小部件

[英]Drupal text module multiline widget for varchar field

Correct me if I'm wrong, but varchar in database is better for performance if you have multiple fields per node. 如果我错了,请纠正我,但是如果每个节点有多个字段,则数据库中的varchar的性能会更好。 Now if I select multiline text - I automaticaly get text field in database which is what I don't want. 现在,如果我选择多行文本-我会自动获取数据库中不需要的文本字段。

To get multiline in text fields I could hack text.module and get what I want with one additional word like this: 为了在文本字段中获得多行,我可以修改text.module并使用一个额外的单词来得到我想要的东西:

Instead of: 代替:

function text_field_widget_info() { return array( ... 'text_textarea' => array( ... 'field types' => array('text_long'), ... ), ... change to: function text_field_widget_info() { return array( ... 'text_textarea' => array( ... 'field types' => array('text_long'), ... ), ...更改为:

function text_field_widget_info() { return array( ... 'text_textarea' => array( ... 'field types' => array('text_long', 'text'), ... ), ...

Changing core modules of course is not good. 更改核心模块当然不好。 Is there any elegant way to hook and extend text module in my own module without rewriting the widget - can I tell to allow textarea not only text_long, but also text? 在不重写小部件的情况下,是否有任何优雅的方法可以在我自己的模块中挂钩和扩展文本模块-我能否告诉我textarea不仅允许text_long,还允许文本?

You can implement hook_field_widget_info_alter() to change the type. 您可以实现hook_field_widget_info_alter()来更改类型。 Don't forget to clear the cache for the changes to be visible. 不要忘记清除缓存以使更改可见。

There's also a module for Text area widget for text fields now which implements hook_field_widget_info_alter() exactly as shown in Aurimas Rekštys' comment to Web-Beest's answer. 现在还有一个用于文本字段的文本区域小部件的模块,该模块完全实现了AurimasRekštys对Web-Beest的回答的注释中所示的hook_field_widget_info_alter() This is useful for anyone who wishes to install a contributed module rather than creating or adding to their own custom module. 对于希望安装贡献模块而不是创建或添加到自己的自定义模块的任何人来说,这很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM