Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / path / src / Plugin / Field / FieldType / PathItem.php
index 4d8da7a8ad7ccd08c8ba081db6eb582a1adadd3c..65cb14bf2b85cf79353fd4ef593b95141402e338 100644 (file)
@@ -17,7 +17,8 @@ use Drupal\Core\TypedData\DataDefinition;
  *   description = @Translation("An entity field containing a path alias and related data."),
  *   no_ui = TRUE,
  *   default_widget = "path",
- *   list_class = "\Drupal\path\Plugin\Field\FieldType\PathFieldItemList"
+ *   list_class = "\Drupal\path\Plugin\Field\FieldType\PathFieldItemList",
+ *   constraints = {"PathAlias" = {}},
  * )
  */
 class PathItem extends FieldItemBase {
@@ -30,6 +31,8 @@ class PathItem extends FieldItemBase {
       ->setLabel(t('Path alias'));
     $properties['pid'] = DataDefinition::create('integer')
       ->setLabel(t('Path id'));
+    $properties['langcode'] = DataDefinition::create('string')
+      ->setLabel(t('Language Code'));
     return $properties;
   }
 
@@ -40,11 +43,20 @@ class PathItem extends FieldItemBase {
     return [];
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function isEmpty() {
+    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);
+    }
   }
 
   /**