field_create_instance的使用。
首先用field_create_field创建字段。
需要注意的是如果字段有设置需要在这里设置。在field_create_instance里面设置的是instance的设置。
看官方文档,注意没有加黑的字,A field instance definition array. The field_name, entity_type and bundle properties are required. Other properties, if omitted, will be given the following default values:
这感觉又是一个坑。
举个例子,坑了我不少时间。
使用entityreference定义的字段entityreferen时,如果不在field_create_field设置好要引用的字段。在field_create_instance只会引用默认的node。