EntityMalformedException: Missing bundle property on entity of type taxonomy_term

Submitted by netllika on Thu, 03/23/2023 - 04:54

Recientemente tuvimos este error en Drupal 7:

EntityMalformedException: Falta la propiedad "bundle" en la entidad de tipo taxonomy_term. en entity_extract_ids() (línea 8090 de /home/mysite/mysite.com/public/includes/common.inc).

Y esta fue la solución:

diff --git a/drupal/includes/common.inc b/drupal/includes/common.inc
index ad2a345..7a511f4 100644
--- a/drupal/includes/common.inc
+++ b/drupal/includes/common.inc
@@ -7785,9 +7785,17 @@ function entity_extract_ids($entity_type, $entity) {
   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)));
+      if($entity_type == "taxonomy_term"){
+        $bundle = $entity_type;
+        $bundle_set_manually = true;
+      }else{
+        throw new EntityMalformedException(t('Missing bundle property on entity of type @entity_type.', array('@entity_type' => $entity_type)));
+      }
     }
-    $bundle = $entity->{$info['entity keys']['bundle']};
+    if(!isset($bundle_set_manually) || !$bundle_set_manually){
+      $bundle = $entity->{$info['entity keys']['bundle']};
+    }
+
   }
   else {
     // The entity type provides no bundle key: assume a single bundle, named
     

Fuente: https://www.drupal.org/node/1270340#comment-9890989