Drupal 核心common.inc 文件抛出错误,条件如下:
if (!empty($info['entity keys']['bundle'])) {
// Explicitly fail for malformed entities missing the bundle property.
if (!isset($entity->{$info['entity keys']['bundle']}) || $entity->{$info['entity keys']['bundle']} === '') {
throw new EntityMalformedException(t('Missing bundle property on entity of type @entity_type.', array('@entity_type' => $entity_type)));
}
$bundle = $entity->{$info['entity keys']['bundle']};
}
因此,如果您的 bundle 属性在保存时格式错误,则会显式失败,因为它无法识别那是什么类型(bundle)。
这可能失败的原因有很多,因此您必须先对其进行分析。
(如果你没有 drush,如果启用了 Devel 模块,你可以在 /devel/php 中运行 PHP 代码)。
-
通过以下方式检查实体信息数组中定义的数组entity keys部分中bundle的值是多少:
drush eval 'print_r(entity_get_info("student"));'
如果是type,则表示您要保存的实体缺少type 属性。
常见的错误通常是通过entity_load() 加载实体并尝试重新保存它,但请记住,返回值是一个由其 id 索引的实体对象数组。
因此,验证您的实体重新保存是否正常工作的简单测试是:
drush eval '$entity = entity_load("student", array(1)); entity_get_controller("student")->save(reset($entity))'
student 是您的entity_type,1 是您的实体 ID。
如果仍然不起作用,请清除缓存 (entity_info_cache_clear()) 或临时编辑您的 common.inc 并转储(例如 var_dump($entity); 您的 $entity 就在 throw 行之前,然后检查传递给函数的内容并进一步调查您的捆绑包type 丢失的原因。
有关更多可能性和详细信息,请查看:How to debug EntityMalformedException? at DO