将字段文本转换为列表(文本)drupal 7
我有一个文本类型的字段,我想将其转换为 Drupal 7 中的列表(文本)类型。我不能简单地更改该值,因为它不允许我这样做,有没有一种简单的方法可以做到这一点?
I have a field that is type text and I want to convert it to type List (text) in Drupal 7. I can't simply change the value, as it won't let me, is there an easy way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有简单的方法,不。据我所知,这些是您需要进行的手动数据库更改:
在
field_config
中将type
列更改为“list_text”和module
列来“列出”您的字段。然后,您需要更改
data
列中的序列化数组以匹配列表类型的序列化数组(显然,它目前具有文本类型的设置)。在这里没有简单的方法向您展示如何执行此操作,最好的方法是将序列化数组与列表类型的不同字段的数组进行比较,然后您将能够看到需要删除/更改哪些值。settings
下的allowed_values
数组将是您放置列表值的位置。更改后,重新序列化它并将其放回字段的data
列中。之后,从字段的
field_data
和field_revision
表中删除所有以field_myfield_
开头但不是field_myfield_value
(列表类型仍然需要该列)。为这些表的
value
列添加索引。清除缓存
我必须警告,这完全未经测试,只是查看表结构似乎有意义,备份您将要使用的三个表是一个好主意以防万一。
There's no easy way, no. As far as I can tell these are the manual DB changes you'll need to make:
In
field_config
change thetype
column to 'list_text' andmodule
column to 'list' for your field.Then you'll need to change the serialised array in the
data
column to match that of a list type (it'll have the settings for text types at the moment obviously). There's no easy way to show you how to do it here, the best way would be to compare the serialised array with one for a different field of a list type, then you'll be able to see what values you need to remove/change. Theallowed_values
array undersettings
will be where you put your list's values. Once that's changed, re-serialise it and put it back in thedata
column for your field.After that remove any columns from your field's
field_data
andfield_revision
tables that begin withfield_myfield_
but aren'tfield_myfield_value
(the list type still needs that column).Add an index to those tables for the
value
column.Clear your caches
I must warn that's completely untested it just seems to make sense looking at the table structures, it'd be a good idea to take a back up of the three tables you'll be playing with just in case.
我刚刚在我的 Helper 模块 中编写了一些应该为您处理此问题的代码:http://cgit.drupalcode.org/helper/tree/lib/FieldChangeHelper.php?h=7.x-1.x
它应该适用于大多数简单的情况和字段,但应进行彻底测试。目前它也不会更新任何字段格式化程序,因此您需要在运行此命令后检查该字段的显示配置。
I just wrote some code that should handle this for you in my Helper module: http://cgit.drupalcode.org/helper/tree/lib/FieldChangeHelper.php?h=7.x-1.x
It should work fine for most simple cases and fields, but should be tested thoroughly. It also currently doesn't update any field formatters, so you'll want to review the display configuration for the field after running this.