Issue #3166668 by akhilavnair, arx-e, poker10, mcdruid, igorbarato, Fabianx: PHP 7.4 and empty entity_keys for taxonomy term result in notices
parent
fada066943
commit
c985a673da
|
@ -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.
|
||||
|
|
|
@ -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.');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue