Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Field / BaseFieldDefinition.php
index c7bb23306d51a4616a05b9b1a56ab98255b39ef5..25df63b5bdb94403c082c37d020fc2357565232b 100644 (file)
@@ -89,7 +89,6 @@ class BaseFieldDefinition extends ListDataDefinition implements FieldDefinitionI
       ->setLabel($definition->getLabel())
       ->setName($definition->getName())
       ->setProvider($definition->getProvider())
-      ->setQueryable($definition->isQueryable())
       ->setRevisionable($definition->isRevisionable())
       ->setSettings($definition->getSettings())
       ->setTargetEntityTypeId($definition->getTargetEntityTypeId())
@@ -287,7 +286,8 @@ class BaseFieldDefinition extends ListDataDefinition implements FieldDefinitionI
    * {@inheritdoc}
    */
   public function isQueryable() {
-    return isset($this->definition['queryable']) ? $this->definition['queryable'] : !$this->isComputed();
+    @trigger_error('BaseFieldDefinition::isQueryable() is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, you should use \Drupal\Core\Field\BaseFieldDefinition::hasCustomStorage(). See https://www.drupal.org/node/2856563.', E_USER_DEPRECATED);
+    return !$this->hasCustomStorage();
   }
 
   /**
@@ -298,8 +298,14 @@ class BaseFieldDefinition extends ListDataDefinition implements FieldDefinitionI
    *
    * @return static
    *   The object itself for chaining.
+   *
+   * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use
+   *   \Drupal\Core\Field\BaseFieldDefinition::setCustomStorage() instead.
+   *
+   * @see https://www.drupal.org/node/2856563
    */
   public function setQueryable($queryable) {
+    @trigger_error('BaseFieldDefinition::setQueryable() is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, you should use \Drupal\Core\Field\BaseFieldDefinition::setCustomStorage(). See https://www.drupal.org/node/2856563.', E_USER_DEPRECATED);
     $this->definition['queryable'] = $queryable;
     return $this;
   }
@@ -503,6 +509,89 @@ class BaseFieldDefinition extends ListDataDefinition implements FieldDefinitionI
     return $this;
   }
 
+  /**
+   * Returns the initial value for the field.
+   *
+   * @return array
+   *   The initial value for the field, as a numerically indexed array of items,
+   *   each item being a property/value array (array() for no default value).
+   */
+  public function getInitialValue() {
+    $value = isset($this->definition['initial_value']) ? $this->definition['initial_value'] : [];
+
+    // Normalize into the "array keyed by delta" format.
+    if (isset($value) && !is_array($value)) {
+      $value = [
+        [$this->getMainPropertyName() => $value],
+      ];
+    }
+
+    return $value;
+  }
+
+  /**
+   * Sets an initial value for the field.
+   *
+   * @param mixed $value
+   *   The initial value for the field. This can be either:
+   *   - a literal, in which case it will be assigned to the first property of
+   *     the first item;
+   *   - a numerically indexed array of items, each item being a property/value
+   *     array;
+   *   - a non-numerically indexed array, in which case the array is assumed to
+   *     be a property/value array and used as the first item;
+   *   - an empty array for no initial value.
+   *
+   * @return $this
+   */
+  public function setInitialValue($value) {
+    // @todo Implement initial value support for multi-value fields in
+    //   https://www.drupal.org/node/2883851.
+    if ($this->isMultiple()) {
+      throw new FieldException('Multi-value fields can not have an initial value.');
+    }
+
+    if ($value === NULL) {
+      $value = [];
+    }
+    // Unless the value is an empty array, we may need to transform it.
+    if (!is_array($value) || !empty($value)) {
+      if (!is_array($value)) {
+        $value = [[$this->getMainPropertyName() => $value]];
+      }
+      elseif (is_array($value) && !is_numeric(array_keys($value)[0])) {
+        $value = [0 => $value];
+      }
+    }
+    $this->definition['initial_value'] = $value;
+
+    return $this;
+  }
+
+  /**
+   * Returns the name of the field that will be used for getting initial values.
+   *
+   * @return string|null
+   *   The field name.
+   */
+  public function getInitialValueFromField() {
+    return isset($this->definition['initial_value_from_field']) ? $this->definition['initial_value_from_field'] : NULL;
+  }
+
+  /**
+   * Sets a field that will be used for getting initial values.
+   *
+   * @param string $field_name
+   *   The name of the field that will be used for getting initial values.
+   *
+   * @return $this
+   */
+  public function setInitialValueFromField($field_name) {
+    $this->definition['initial_value_from_field'] = $field_name;
+
+    return $this;
+  }
+
   /**
    * {@inheritdoc}
    */
@@ -579,7 +668,7 @@ class BaseFieldDefinition extends ListDataDefinition implements FieldDefinitionI
   public function __sleep() {
     // Do not serialize the statically cached property definitions.
     $vars = get_object_vars($this);
-    unset($vars['propertyDefinitions']);
+    unset($vars['propertyDefinitions'], $vars['typedDataManager']);
     return array_keys($vars);
   }