06 avr 2015

Just type "EntityMalformedException" in Google, and you'll realize that this error is both common on Drupal sites and difficult to solve. For my part, I encountered this error when performing the migration of a Drupal site from version 6 to version 7 . This site was built around "Organic groups", which made it a complex migration. Upon activation of the version 7 of the "Organic Groups" module, a message appeared asking me to "Rebuild content access permissions" .Normal. But after trying to reconstruct these permissions, I got this fatal error : "EntityMalformedException: Missing bundle property on entity types of node in entity_extract_ids () .... in /includes/common.inc 7789 line.".

What does this error mean?

In one of the bundle of the entity of type "node", a property was missing ($ Bundle-> property).

 

Let's resolve it.

We know where the display of this error is triggered ("/includes/common.inc 7789 line"), we have to know what triggers it. For that let's use the PHP function : debug_print_backtrace () This function displays the PHP execution stack and allows us to review the events that happened before the error display. 7789 line of /includes/common.inc is this code:

// Explicitly fail for malformed entities bundle the missing property.
    if (isset ($ entity -> {$ info ['entity keys'] [' bundle ']}) || $ entity -> {$ info [' entity keys'] ['bundle']} === ' ') {
      throw new EntityMalformedException (t ('Missing bundle property on entity types ofentity_type.', array ('@ entity_type' => $ entity_type)));
    }

So we will insert

 dpm (debug_print_backtrace ()); 

just before the call to the exception: (To use the dpm () function, you must have installed the Devel Module).

// Explicitly fail for malformed entities bundle the missing property.
    if (isset ($ entity -> {$ info ['entity keys'] [' bundle ']}) || $ entity -> {$ info [' entity keys'] ['bundle']} === ' ') {
      dpm (debug_print_backtrace ());
      throw new EntityMalformedException (t ('Missing bundle property on entity types ofentity_type.', array ('@ entity_type' => $ entity_type)));
    }

In the resulting display, look for the "node" and "nid" , since the error deals with "nodes". For me, there were three nodes, node / 5561 node / 5562 and node / 5563. I could see that the type was empty (type =>). To find that, I simply went to PhpMyadmin in the "node" table and filtered by "type". These three "nodes" had an empty Type . After their removal, everything was back to normal, I could rebuild the permissions ang go on with the Drupal migration process !

Drupal migration rule of thumb

As a side note, before performing any migration, check that in the old table you can't find any orphaned node. That will save you all this hassle !