The error:
EntityMalformedException: Missing bundle property on entity of type node.
happens, because your bundle property is malformed either on load or save, and it basically can't identify what type (bundle) is it.
This could be potentially caused by variety of things such us:
saving invalid entity such as:
- missing
type
from the node object (e.g. wrongly generated by Devel Generate?);
- missing
orphaned nodes in node table;
having orphaned nodes, caused by:
- search view having indexed nodes which aren't in the system;
- other modules (like Feeds) removing nodes from Drupal improperly;
nodes having invalid/non-existing references; for term data this can be checked by:
drush sqlq "SELECT nid, title from node WHERE nid IN (select entity_id from field_data_field_some_ref WHERE field_some_ref_tid not IN (select tid from taxonomy_term_data));"
Where
field_data_field_some_ref
is data field offield_some_ref
which is type of 'Term reference'.See: DB records not deleted for Term Reference Fields after Term is Deleted
having orphaned taxonomy terms (so you may use Taxonomy Orphanage);
invalid custom code (human error) such as:
- badly implemented Entity API,
- badly implemented CTools/Form API,
!empty()
test on the entity variable before callingfield_get_items()
,- rendering field by invalid calls,
- triggering functions which shouldn't be triggered on certain pages (e.g. field_view_field()),
Here is the responsible code which is thrown by Drupal core (file: 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']};
}
Debugging
If you don't recognise anything above, the easiest thing to debug that kind of error is by placing var_dump(debug_backtrace());
or dd(debug_backtrace());
(when Devel is on) before the actual throw new EntityMalformedException
on the affected line in common.inc
.
If this is happening on node save, check this EntityMalformedException post at SO for more detailed instructions.
See also the following Drupal issue: #1778572 for more ideas.