Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / path / src / Plugin / Field / FieldType / PathFieldItemList.php
index ee03361d961d5c6f2057d348103227fde81b9228..1a5fbe0858e0e51774cf9315646e2842b74dcc1d 100644 (file)
@@ -5,12 +5,42 @@ namespace Drupal\path\Plugin\Field\FieldType;
 use Drupal\Core\Access\AccessResult;
 use Drupal\Core\Field\FieldItemList;
 use Drupal\Core\Session\AccountInterface;
+use Drupal\Core\TypedData\ComputedItemListTrait;
 
 /**
  * Represents a configurable entity path field.
  */
 class PathFieldItemList extends FieldItemList {
 
+  use ComputedItemListTrait;
+
+  /**
+   * {@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
+      //   https://www.drupal.org/node/2511968.
+      $alias = \Drupal::service('path.alias_storage')->load([
+        'source' => '/' . $entity->toUrl()->getInternalPath(),
+        'langcode' => $this->getLangcode(),
+      ]);
+
+      if ($alias) {
+        $value = $alias;
+      }
+    }
+
+    $this->list[0] = $this->createItem(0, $value);
+  }
+
   /**
    * {@inheritdoc}
    */