$this->
fail('Using a field of a different type as initial value does not work.'
);
} catch (FieldException
$e) { $this->
assertEquals('Illegal initial value definition on new_base_field: The field types do not match.',
$e->
getMessage());
} try { // Add a base field that will not be stored in the shared tables.
$initial_field = BaseFieldDefinition::
create('string'
) ->
setName('initial_field'
) ->
setLabel(t('An initial field'
)) ->
setCardinality(2
);
$this->state->
set('entity_test_update.additional_base_field_definitions',
['initial_field' =>
$initial_field]);
$this->entityDefinitionUpdateManager->
installFieldStorageDefinition('initial_field', 'entity_test_update', 'entity_test',
$initial_field);
// Now add the base field which will try to use the previously added field
// as the source of its initial values.
$new_base_field = BaseFieldDefinition::
create('string'
) ->
setName('new_base_field'
) ->
setLabel(t('A new base field'
)) ->
setInitialValueFromField('initial_field'
);
$this->state->
set('entity_test_update.additional_base_field_definitions',
['initial_field' =>
$initial_field, 'new_base_field' =>
$new_base_field]);
$this->entityDefinitionUpdateManager->
installFieldStorageDefinition('new_base_field', 'entity_test_update', 'entity_test',
$new_base_field);