Mercurial > hg > isophonics-drupal-site
diff core/lib/Drupal/Core/Field/BaseFieldDefinition.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | c2387f117808 |
children | af1871eacc83 |
line wrap: on
line diff
--- a/core/lib/Drupal/Core/Field/BaseFieldDefinition.php Tue Jul 10 15:07:59 2018 +0100 +++ b/core/lib/Drupal/Core/Field/BaseFieldDefinition.php Thu Feb 28 13:21:36 2019 +0000 @@ -15,6 +15,7 @@ class BaseFieldDefinition extends ListDataDefinition implements FieldDefinitionInterface, FieldStorageDefinitionInterface, RequiredFieldStorageDefinitionInterface { use UnchangingCacheableDependencyTrait; + use FieldInputValueNormalizerTrait; /** * The field type. @@ -470,14 +471,7 @@ else { $value = $this->getDefaultValueLiteral(); } - // Normalize into the "array keyed by delta" format. - if (isset($value) && !is_array($value)) { - $properties = $this->getPropertyNames(); - $property = reset($properties); - $value = [ - [$property => $value], - ]; - } + $value = $this->normalizeValue($value, $this->getMainPropertyName()); // Allow the field type to process default values. $field_item_list_class = $this->getClass(); return $field_item_list_class::processDefaultValue($value, $entity, $this); @@ -522,16 +516,7 @@ * 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; + return $this->normalizeValue($this->definition['initial_value'], $this->getMainPropertyName()); } /** @@ -556,20 +541,7 @@ 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; - + $this->definition['initial_value'] = $this->normalizeValue($value, $this->getMainPropertyName()); return $this; }