Commit c985a673 authored by Drew Webber's avatar Drew Webber
Browse files

Issue #3166668 by akhilavnair, arx-e, poker10, mcdruid, igorbarato, Fabianx:...

Issue #3166668 by akhilavnair, arx-e, poker10, mcdruid, igorbarato, Fabianx: PHP 7.4 and empty entity_keys for taxonomy term result in notices
parent fada0669
Loading
Loading
Loading
Loading
+6 −0
Changes for includes/common.inc: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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.
  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.
+12 −0
Changes for modules/field/tests/field.test: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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.');
  }
}