@@ -367,10 +367,10 @@ protected function preSaveUpdated(EntityStorageInterface $storage) {
// Some updates are always disallowed.
if($this->getType()!=$this->original->getType()){
thrownewFieldException("Cannot change the field type for an existing field storage.");
thrownewFieldException(sprintf('Cannot change the field type for an existing field storage. The field storage %s has the type %s.',$this->id(),$this->original->getType()));
thrownewFieldException("Cannot change the entity type for an existing field storage.");
thrownewFieldException(sprintf('Cannot change the entity type for an existing field storage. The field storage %s has the type %s.',$this->id(),$this->original->getTargetEntityTypeId()));
}
// See if any module forbids the update by throwing an exception. This
@@ -383,6 +383,42 @@ public function testUpdateFieldType() {
}
}
/**
* Test changing a field storage type.
*/
publicfunctiontestUpdateEntityType(){
$field_storage=FieldStorageConfig::create([
'field_name'=>'field_type',
'entity_type'=>'entity_test',
'type'=>'decimal',
]);
$field_storage->save();
$this->expectException(FieldException::class);
$this->expectExceptionMessage('Cannot change the field type for an existing field storage. The field storage entity_test.field_type has the type decimal.');
$field_storage->set('type','foobar');
$field_storage->save();
}
/**
* Test changing a field storage entity type.
*/
publicfunctiontestUpdateEntityTargetType(){
$field_storage=FieldStorageConfig::create([
'field_name'=>'field_type',
'entity_type'=>'entity_test',
'type'=>'decimal',
]);
$field_storage->save();
$this->expectException(FieldException::class);
$this->expectExceptionMessage('Cannot change the entity type for an existing field storage. The field storage foobar.field_type has the type entity_test.');