summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2011-07-28 17:31:28 -0400
committerwebchick <webchick@24967.no-reply.drupal.org>2011-07-28 17:31:28 -0400
commite7faaccb16bd847a88ddac763c3b66480a740642 (patch)
treef81802ac837cc90e79d39808f7388d79fe87c814 /includes
parent18777c174e5a80c1272f501c2bee59955535a32e (diff)
downloadbrdo-e7faaccb16bd847a88ddac763c3b66480a740642.tar.gz
brdo-e7faaccb16bd847a88ddac763c3b66480a740642.tar.bz2
Issue #1067750 by yched, fago: Let Field API fail in a tale-telling way on invalid .
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc18
-rw-r--r--includes/entity.inc5
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 { }