diff --git a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php index fe6886a..e9f5463 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php @@ -345,6 +345,33 @@ public function save() { // Otherwise, the field is being updated. else { $original = $storage_controller->loadUnchanged($this->id()); + // Ensure this field ID does not exist with a different UUID. + if ($original->uuid != $this->uuid) { + throw new FieldException(format_string( + 'Attempt to create a field @input_id with UUID @input_uuid when this field already exists with UUID @field_uuid', + array( + '@input_id' => $this->id, + '@input_uuid' => $this->uuid, + '@field_uuid' => $original->uuid, + ) + )); + } + // Ensure this field UUID does not exist with a different ID. + // @todo Adding this dependency here might be bad. + $matching_fields = \Drupal::entityQuery('field_instance') + ->condition('uuid', $values['uuid']) + ->execute(); + $matched_field = current($matching_fields); + if (!empty($matched_field) && $matched_field['id'] != $this->id) { + throw new FieldException(format_string( + 'Attempt to create a field @input_id with UUID @input_uuid when this UUID is already used for @field_id', + array( + '@input_id' => $this->id, + '@input_uuid' => $this->uuid, + '@field_id' => $matched_fied['id'], + ) + )); + } // Some updates are always disallowed. if ($this->type != $original->type) {