1

我通过自定义模块创建了一个实体。该实体没有任何捆绑包,并且创建得非常好。entity_get_info 表示不需要捆绑。

接下来,我使用 field_create_field 为实体引用创建一个字段,它也可以正常工作。现在,当我想将此字段作为实例关联到我的自定义实体并且当我调用 field_create_instance (不指定捆绑包)时,我收到错误消息:

drupal FieldException:尝试创建没有包的字段实例

我继续看到 bundle 是 field_config_instance 中的必填字段。我试图将 bundle 指定为与​​实体相同的名称,但这对我也不起作用。实际上,它确实创建了一个实例,但是当我执行 field_attach_form 时,在实体添加/编辑表单上,我收到另一个错误:

注意:未定义索引:EntityReferenceHandler_base->buildEntityFieldQuery() 中的 target_bundles(/Applications/MAMP/htdocs/MYPROJECT/sites/all/modules/entityreference/handler/base.inc 的第 174 行)。

任何帮助将不胜感激。

4

1 回答 1

3

When creating an instance for your field, you need to make sure you specify the bundle name. In case you dont have any bundles for your entity, by default a single bundle is created with the same name as that of your entity. This is what helped:

'entity_type' => 'MY_ENTITY', 'bundle' => 'MY_ENTITY',

The entire workflow can be reached at my blog: Use entity reference in your custom entities without bundles

于 2011-12-08T08:43:33.020 回答