Issue #3166668 by akhilavnair, arx-e, poker10, mcdruid, igorbarato, Fabianx: PHP 7.4 and empty entity_keys for taxonomy term result in notices

merge-requests/2343/head
mcdruid 2022-05-27 09:32:44 +01:00
parent fada066943
commit c985a673da
2 changed files with 20 additions and 2 deletions

View File

@ -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.

View File

@ -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.');
}
}