+ /**
+ * 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() {
+ return $this->normalizeValue($this->definition['initial_value'], $this->getMainPropertyName());
+ }
+
+ /**
+ * 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.');
+ }
+
+ $this->definition['initial_value'] = $this->normalizeValue($value, $this->getMainPropertyName());
+ 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.
+ * @param mixed $default_value
+ * (optional) The default value for the field, in case the inherited value
+ * is NULL. 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.
+ * If the field being added is required or an entity key, it is recommended
+ * to provide a default value.
+ *
+ * @return $this
+ */
+ public function setInitialValueFromField($field_name, $default_value = NULL) {
+ $this->definition['initial_value_from_field'] = $field_name;
+ $this->setInitialValue($default_value);
+ return $this;
+ }
+