$initial_value =
$initial_value_from_field =
[];
$storage_definition_is_new =
empty($this->
loadFieldSchemaData($storage_definition));
if ($storage_definition_is_new &&
$storage_definition instanceof BaseFieldDefinition &&
$table_mapping->
allowsSharedTableStorage($storage_definition)) { if (($initial_storage_value =
$storage_definition->
getInitialValue()) && !
empty($initial_storage_value)) { // We only support initial values for fields that are stored in shared
// tables (i.e. single-value fields).
// @todo Implement initial value support for multi-value fields in
// https://www.drupal.org/node/2883851.
$initial_value =
reset($initial_storage_value);
} if ($initial_value_field_name =
$storage_definition->
getInitialValueFromField()) { // Check that the field used for populating initial values is valid.
if (!
isset($this->fieldStorageDefinitions
[$initial_value_field_name])) { throw new FieldException("Illegal initial value definition on {
$storage_definition->
getName()}: The field
$initial_value_field_name does not exist."
);
} if ($storage_definition->
getType() !==
$this->fieldStorageDefinitions
[$initial_value_field_name]->
getType()) { throw new FieldException("Illegal initial value definition on {
$storage_definition->
getName()}: The field types do not match."
);
} if (!
$table_mapping->
allowsSharedTableStorage($this->fieldStorageDefinitions
[$initial_value_field_name])) { throw new FieldException("Illegal initial value definition on {
$storage_definition->
getName()}: Both fields have to be stored in the shared entity tables."
);
}