X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fpath%2Fsrc%2FPlugin%2FField%2FFieldType%2FPathItem.php;fp=web%2Fcore%2Fmodules%2Fpath%2Fsrc%2FPlugin%2FField%2FFieldType%2FPathItem.php;h=fc263ce60afcdd573b6df721448c5507a619b776;hb=1c1cb0980bfa6caf0c24cce671b6bb541dc87583;hp=cd62bea662e6121be96bddaff95c7ae21a5c7c9b;hpb=9424afc6c1f518c301bf87a23c047d1873435d05;p=yaffs-website diff --git a/web/core/modules/path/src/Plugin/Field/FieldType/PathItem.php b/web/core/modules/path/src/Plugin/Field/FieldType/PathItem.php index cd62bea66..fc263ce60 100644 --- a/web/core/modules/path/src/Plugin/Field/FieldType/PathItem.php +++ b/web/core/modules/path/src/Plugin/Field/FieldType/PathItem.php @@ -63,10 +63,15 @@ class PathItem extends FieldItemBase { * {@inheritdoc} */ public function postSave($update) { + // If specified, rely on the langcode property for the language, so that the + // existing language of an alias can be kept. That could for example be + // unspecified even if the field/entity has a specific langcode. + $alias_langcode = ($this->langcode && $this->pid) ? $this->langcode : $this->getLangcode(); + if (!$update) { if ($this->alias) { $entity = $this->getEntity(); - if ($path = \Drupal::service('path.alias_storage')->save('/' . $entity->urlInfo()->getInternalPath(), $this->alias, $this->getLangcode())) { + if ($path = \Drupal::service('path.alias_storage')->save('/' . $entity->urlInfo()->getInternalPath(), $this->alias, $alias_langcode)) { $this->pid = $path['pid']; } } @@ -79,7 +84,7 @@ class PathItem extends FieldItemBase { // Only save a non-empty alias. elseif ($this->alias) { $entity = $this->getEntity(); - \Drupal::service('path.alias_storage')->save('/' . $entity->urlInfo()->getInternalPath(), $this->alias, $this->getLangcode(), $this->pid); + \Drupal::service('path.alias_storage')->save('/' . $entity->urlInfo()->getInternalPath(), $this->alias, $alias_langcode, $this->pid); } } }