Skip to main content
8 of 8
Adds link.
kenorb
  • 14.3k
  • 10
  • 98
  • 168

The error:

EntityMalformedException: Missing bundle property on entity of type node.

happens, because your bundle property is malformed either on load or save, so Drupal can't find what type of bundle is it.

The logic of that Exception is:

// Explicitly fail for malformed entities missing the bundle property.
if (!isset($entity->{$info['entity keys']['bundle']}) || $entity->{$info['entity keys']['bundle']} === '') {
  // var_dump(debug_backtrace()); exit; // You may want this line to debug.
  throw new EntityMalformedException(t('Missing bundle property on entity of type @entity_type.', array('@entity_type' => $entity_type)));
}

So basically value of $info['entity keys']['bundle'] (for node it's: type) can't be found in $entity object ($node->type for the node), therefore Drupal doesn't know with what kind of entity it's dealing with. So most likely your entity is invalid (e.g. you're loading something else instead) or it is just empty ($entity is NULL).


If you haven't modified any Drupal code, this potentially can be caused by variety of things (most likely by specific Drupal module bug), such as:

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.

Note: Using dd() function from Devel will generate the debugging info to the file in your Drupal temp folder (temporary://drupal_debug.txt) with backtrace dump, otherwise could be too big and difficult to read when dumping on the screen. When using var_dump(), it's easier to call die(); after the call and check the dump in the view-source mode of the page.

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.

kenorb
  • 14.3k
  • 10
  • 98
  • 168