diff options
-rw-r--r-- | includes/common.inc | 18 | ||||
-rw-r--r-- | includes/entity.inc | 5 |
2 files changed, 20 insertions, 3 deletions
diff --git a/includes/common.inc b/includes/common.inc index 86a70c041..8849ef83c 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -7372,12 +7372,24 @@ function entity_info_cache_clear() { */ function entity_extract_ids($entity_type, $entity) { $info = entity_get_info($entity_type); + // Objects being created might not have id/vid yet. $id = isset($entity->{$info['entity keys']['id']}) ? $entity->{$info['entity keys']['id']} : NULL; $vid = ($info['entity keys']['revision'] && isset($entity->{$info['entity keys']['revision']})) ? $entity->{$info['entity keys']['revision']} : NULL; - // If no bundle key provided, then we assume a single bundle, named after the - // entity type. - $bundle = $info['entity keys']['bundle'] ? $entity->{$info['entity keys']['bundle']} : $entity_type; + + 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']}; + } + else { + // The entity type provides no bundle key: assume a single bundle, named + // after the entity type. + $bundle = $entity_type; + } + return array($id, $vid, $bundle); } diff --git a/includes/entity.inc b/includes/entity.inc index f363c3113..1eb40c56d 100644 --- a/includes/entity.inc +++ b/includes/entity.inc @@ -1327,3 +1327,8 @@ class EntityFieldQuery { } } + +/** + * Exception thrown when a malformed entity is passed. + */ +class EntityMalformedException extends Exception { } |