diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index 9406927..fd92c61 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -387,7 +387,18 @@ 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. + $values = $field->getValue(); + if (is_array($values)) { + foreach($values as $key => $value) { + if ($value === NULL) { + unset($values[$key]); + } + } + } + $this->values[$name][$langcode] = $values; } } } 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 c8bed9a..13e2c38 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->value, $term2->name->value); + + // 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/forum/forum.module b/core/modules/forum/forum.module index af1330e..b00240a 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -334,10 +334,13 @@ function forum_node_presave(EntityInterface $node) { $langcode = key($node->taxonomy_forums); if (!empty($node->taxonomy_forums[$langcode])) { $node->forum_tid = $node->taxonomy_forums[$langcode][0]['tid']; - $old_tid = db_query_range("SELECT f.tid FROM {forum} f INNER JOIN {node} n ON f.vid = n.vid WHERE n.nid = :nid ORDER BY f.vid DESC", 0, 1, array(':nid' => $node->nid))->fetchField(); - if ($old_tid && isset($node->forum_tid) && ($node->forum_tid != $old_tid) && !empty($node->shadow)) { - // A shadow copy needs to be created. Retain new term and add old term. - $node->taxonomy_forums[$langcode][] = array('tid' => $old_tid); + // Only do a shadow copy check if this is not a new node. + if (!$node->isNew()) { + $old_tid = db_query_range("SELECT f.tid FROM {forum} f INNER JOIN {node} n ON f.vid = n.vid WHERE n.nid = :nid ORDER BY f.vid DESC", 0, 1, array(':nid' => $node->nid))->fetchField(); + if ($old_tid && isset($node->forum_tid) && ($node->forum_tid != $old_tid) && !empty($node->shadow)) { + // A shadow copy needs to be created. Retain new term and add old term. + $node->taxonomy_forums[$langcode][] = array('tid' => $old_tid); + } } } } 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(); } }