.../path/src/Plugin/Field/FieldType/PathItem.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/core/modules/path/src/Plugin/Field/FieldType/PathItem.php b/core/modules/path/src/Plugin/Field/FieldType/PathItem.php index 4106381..31901ad 100644 --- a/core/modules/path/src/Plugin/Field/FieldType/PathItem.php +++ b/core/modules/path/src/Plugin/Field/FieldType/PathItem.php @@ -114,6 +114,17 @@ public function set($property_name, $value, $notify = TRUE) { /** * {@inheritdoc} */ + public function setValue($values, $notify = TRUE) { + // Also ensure that existing values are loaded when setting a value, this + // ensures that it is possible to set a new value immediately after loading + // an entity. + $this->ensureLoaded(); + return parent::setValue($values, $notify); + } + + /** + * {@inheritdoc} + */ public function postSave($update) { if (!$update) { if ($this->alias) { @@ -162,7 +173,9 @@ public static function mainPropertyName() { * https://www.drupal.org/node/2392845. */ protected function ensureLoaded() { - if (!$this->isLoaded) { + static $is_loading = FALSE; + + if (!$this->isLoaded && !$is_loading) { $entity = $this->getEntity(); if (!$entity->isNew()) { // @todo Support loading languge neutral aliases in @@ -172,7 +185,9 @@ protected function ensureLoaded() { 'langcode' => $this->getLangcode(), ]); if ($alias) { + $is_loading = TRUE; $this->setValue($alias); + $is_loading = FALSE; } else { // If there is no existing alias, default the langcode to the current