diff --git a/includes/common.inc b/includes/common.inc index a65139f713..b6bc8ad470 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -8034,8 +8034,14 @@ 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 (!empty($info)) { + $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; + } + else { + $id = NULL; + $vid = NULL; + } if (!empty($info['entity keys']['bundle'])) { // Explicitly fail for malformed entities missing the bundle property. diff --git a/modules/field/tests/field.test b/modules/field/tests/field.test index 5312f2d455..c334661aa1 100644 --- a/modules/field/tests/field.test +++ b/modules/field/tests/field.test @@ -3788,4 +3788,16 @@ class EntityPropertiesTestCase extends FieldTestCase { } } } + + /** + * Tests entity_extract_ids() with an empty entity info. + */ + function testEntityKeys(){ + $entity_type = 'test_entity2'; + $entity = field_test_create_stub_entity(); + list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); + + $this->assertNull($id, 'Entity id for test_entity2 returned NULL.'); + $this->assertNull($vid, 'Entity vid for test_entity2 returned NULL.'); + } }