diff --git a/core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php b/core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php index 8488c7e..1a5fbe0 100644 --- a/core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php +++ b/core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php @@ -18,6 +18,12 @@ class PathFieldItemList extends FieldItemList { * {@inheritdoc} */ protected function computeValue() { + // Default the langcode to the current language if this is a new entity or + // there is no alias for an existent entity. + // @todo Set the langcode to not specified for untranslatable fields + // in https://www.drupal.org/node/2689459. + $value = ['langcode' => $this->getLangcode()]; + $entity = $this->getEntity(); if (!$entity->isNew()) { // @todo Support loading languge neutral aliases in @@ -30,16 +36,9 @@ protected function computeValue() { if ($alias) { $value = $alias; } - else { - // If there is no existing alias, default the langcode to the current - // language. - // @todo Set the langcode to not specified for untranslatable fields - // in https://www.drupal.org/node/2689459. - $value = ['langcode' => $this->getLangcode()]; - } - - $this->list[0] = $this->createItem(0, $value); } + + $this->list[0] = $this->createItem(0, $value); } /** diff --git a/core/modules/path/src/Plugin/Field/FieldType/PathItem.php b/core/modules/path/src/Plugin/Field/FieldType/PathItem.php index ea21dac..65cb14b 100644 --- a/core/modules/path/src/Plugin/Field/FieldType/PathItem.php +++ b/core/modules/path/src/Plugin/Field/FieldType/PathItem.php @@ -47,14 +47,16 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) * {@inheritdoc} */ public function isEmpty() { - return ($this->alias === NULL || $this->alias === '') && ($this->pid === NULL || $this->pid === ''); + return ($this->alias === NULL || $this->alias === '') && ($this->pid === NULL || $this->pid === '') && ($this->langcode === NULL || $this->langcode === ''); } /** * {@inheritdoc} */ public function preSave() { - $this->alias = trim($this->alias); + if ($this->alias !== NULL) { + $this->alias = trim($this->alias); + } } /** diff --git a/core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php b/core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php index ad3f02e..d3abef6 100644 --- a/core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php +++ b/core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php @@ -22,7 +22,6 @@ public function normalize($entity, $format = NULL, array $context = []) { $attributes = []; foreach ($entity as $name => $field_items) { - $field_items->filterEmptyItems(); if ($field_items->access('view', $context['account'])) { $attributes[$name] = $this->serializer->normalize($field_items, $format, $context); }