diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index 00f546e..c74c9d5 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -383,7 +383,7 @@ public function updateOriginalValues() { foreach ($this->getPropertyDefinitions() as $name => $definition) { if (empty($definition['computed']) && !empty($this->fields[$name])) { foreach ($this->fields[$name] as $langcode => $field) { - $field->cleanValue(); + $field->filterEmptyValues(); $this->values[$name][$langcode] = $field->getValue(); } } diff --git a/core/lib/Drupal/Core/Entity/Field/FieldInterface.php b/core/lib/Drupal/Core/Entity/Field/FieldInterface.php index 63b6dd0..dc05036 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldInterface.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldInterface.php @@ -28,11 +28,9 @@ interface FieldInterface extends ListInterface, AccessibleInterface { /** - * Cleans the field value. - * - * Removes empty field items and re-numbers the item deltas. + * Filters out empty field items and re-numbers the item deltas. */ - public function cleanValue(); + public function filterEmptyValues(); /** * Gets a property object from the first field item. diff --git a/core/lib/Drupal/Core/Entity/Field/Type/Field.php b/core/lib/Drupal/Core/Entity/Field/Type/Field.php index 50cd51d..618da1c 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/Field.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/Field.php @@ -51,14 +51,11 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface /** * {@inheritdoc} */ - public function cleanValue() { + public function filterEmptyValues() { if (isset($this->list)) { - foreach ($this->list as $delta => $item) { - if ($item->isEmpty()) { - unset($this->list[$delta]); - } - } - $this->list = array_values($this->list); + $this->list = array_values(array_filter($this->list, function($item) { + return !$item->isEmpty(); + })); } } diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index af1330e..04c454a 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -332,7 +332,7 @@ function forum_node_presave(EntityInterface $node) { $node->icon = !empty($node->icon) ? $node->icon : ''; reset($node->taxonomy_forums); $langcode = key($node->taxonomy_forums); - if (!empty($node->taxonomy_forums[$langcode])) { + if (!empty($node->taxonomy_forums[$langcode]) && !$node->isNew()) { $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)) {