You are here

function options_field_storage_config_update_forbid in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 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 108
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(t('A list field (@field_name) with existing data cannot have its keys changed.', array(
        '@field_name' => $field_storage
          ->getName(),
      )));
    }
  }
}