Unverified Commit acb56802 authored by alexpott's avatar alexpott
Browse files

Issue #3050264 by rloos289, jhedstrom, alexpott: Better error message for field storage changes

parent 09d69a9f
......@@ -367,10 +367,10 @@ protected function preSaveUpdated(EntityStorageInterface $storage) {
// Some updates are always disallowed.
if ($this->getType() != $this->original->getType()) {
throw new FieldException("Cannot change the field type for an existing field storage.");
throw new FieldException(sprintf('Cannot change the field type for an existing field storage. The field storage %s has the type %s.', $this->id(), $this->original->getType()));
}
if ($this->getTargetEntityTypeId() != $this->original->getTargetEntityTypeId()) {
throw new FieldException("Cannot change the entity type for an existing field storage.");
throw new FieldException(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.
*/
public function testUpdateEntityType() {
$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.
*/
public function testUpdateEntityTargetType() {
$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.');
$field_storage->set('entity_type', 'foobar');
$field_storage->save();
}
/**
* Test updating a field storage.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment