在 Drupal 中,是否不可能将字段关联到没有捆绑包的实体?
我已经通过自定义模块创建了一个实体。该实体没有任何捆绑包,并且创建得非常好。 entity_get_info表示没有必要有捆绑包。
接下来,我使用 field_create_field 创建一个用于实体引用的字段,效果也很好。现在,当我想将此字段作为实例关联到我的自定义实体时,并且当我调用 field_create_instance (不指定捆绑包)时,我收到错误消息:
drupal FieldException:尝试创建没有捆绑包的字段实例
我继续看到捆绑包是 field_config_instance 中的必填字段..我尝试将捆绑包指定为与实体同名,但这对我来说也不起作用。实际上,它确实创建了一个实例,但在实体添加/编辑表单上,当我执行 field_attach_form 时,我收到另一个错误:
注意:EntityReferenceHandler_base->buildEntityFieldQuery() 中未定义索引:target_bundles(/Applications/MAMP/htdocs/MYPROJECT/sites/all/modules/entityreference/handler/base.inc 第 174 行)。
任何帮助将不胜感激。
I have created an entity via custom module. This entity does not have any bundle and it gets created perfectly fine. entity_get_info says it is not necessary to have bundles.
Next, I create a field for entity reference using field_create_field and that works fine too. Now, when i want to associate this field as an instance to my custom entity and when I call field_create_instance (without specifying bundle), I get the error saying:
drupal FieldException: Attempt to create an instance of field without a bundle
I go on to see that bundle is a required field in field_config_instance .. I tried to specify bundle as the same name as entity but that did not work for me either. Actually, it did create an instance but on the entity add/edit form when I do a field_attach_form, I get another error:
Notice: Undefined index: target_bundles in EntityReferenceHandler_base->buildEntityFieldQuery() (line 174 of /Applications/MAMP/htdocs/MYPROJECT/sites/all/modules/entityreference/handler/base.inc).
Any help will be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为您的字段创建实例时,您需要确保指定包名称。如果您的实体没有任何捆绑包,则默认情况下会创建一个与您的实体同名的捆绑包。这就是有帮助的:
'entity_type' => 'MY_ENTITY',
'捆绑' => 'MY_ENTITY',
整个工作流程可以在我的博客上找到:在没有捆绑包的自定义实体中使用实体引用
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