diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index 70ac362..161a0f9 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -389,7 +389,15 @@ public function updateOriginalValues() { foreach ($this->getPropertyDefinitions() as $name => $definition) { if (empty($definition['computed']) && !empty($this->fields[$name])) { foreach ($this->fields[$name] as $langcode => $field) { - $this->values[$name][$langcode] = $field->getValue(); + // If the value is array we need to filter out potential harmfull + // values like array(0 => NULL) before sending to storage mechanisms + // so that we avoid potential exceptions / empty values stored in + // the database or other storage locations. + $value = $field->getValue(); + if (is_array($value)) { + $value = array_filter($value); + } + $this->values[$name][$langcode] = $value; } } } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php index cc089fb..5319a1d 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php @@ -97,5 +97,11 @@ public function testEntityReferenceItem() { $entity->field_test_taxonomy->target_id = $term2->id(); $this->assertEqual($entity->field_test_taxonomy->entity->id(), $term2->id()); $this->assertEqual($entity->field_test_taxonomy->entity->name, $term2->name); + + // Delete terms so we have nothing to reference and try again + $term->delete(); + $term2->delete(); + $entity = entity_create('entity_test', array('name' => $this->randomName())); + $entity->save(); } } diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php index 7f863cf..73cf876 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php @@ -111,6 +111,11 @@ public function testImageItem() { // Check that the image item can be set to the referenced file directly. $entity->image_test = $this->image; $this->assertEqual($entity->image_test->fid, $this->image->id()); + + // Delete the image and try to save the entity again. + $this->image->delete(); + $entity = entity_create('entity_test', array('mame' => $this->randomName())); + $entity->save(); } }