Same name and namespace in other branches
  1. 8.9.x core/modules/options/options.module \options_field_storage_config_update_forbid()
  2. 9 core/modules/options/options.module \options_field_storage_config_update_forbid()

Implements hook_field_storage_config_update_forbid().

File

core/modules/options/options.module, line 109
Defines selection, check box and radio button widgets for text and numeric fields.

Code

function options_field_storage_config_update_forbid(FieldStorageConfigInterface $field_storage, FieldStorageConfigInterface $prior_field_storage) {
  if ($field_storage
    ->getTypeProvider() == 'options' && $field_storage
    ->hasData()) {

    // Forbid any update that removes allowed values with actual data.
    $allowed_values = $field_storage
      ->getSetting('allowed_values');
    $prior_allowed_values = $prior_field_storage
      ->getSetting('allowed_values');
    $lost_keys = array_keys(array_diff_key($prior_allowed_values, $allowed_values));
    if (_options_values_in_use($field_storage
      ->getTargetEntityTypeId(), $field_storage
      ->getName(), $lost_keys)) {
      throw new FieldStorageDefinitionUpdateForbiddenException("A list field '{$field_storage->getName()}' with existing data cannot have its keys changed.");
    }
  }
}