1 field.module | field_config_update_validate(Config $staging_config, Config $active_config, $all_changes) |
Implements hook_config_update_validate().
Related topics
File
- core/
modules/ field/ field.module, line 503 - Attach custom data fields to Backdrop entities.
Code
function field_config_update_validate(Config $staging_config, Config $active_config, $all_changes) {
$config_name = $staging_config->getName();
// Field validation.
if (strpos($config_name, 'field.field.') === 0) {
// Ensure the field type does not change in updates. Fields must be manually
// deleted and then imported if changing a field type.
$field_name = str_replace('field.field.', '', $config_name);
$current_type = $active_config->get('type');
$new_type = $staging_config->get('type');
if ($current_type !== $new_type) {
throw new ConfigValidateException(t('The field "@name" cannot be created because another field with the same name already exists and is a different type of field. The current type is "@current" and the imported type would be "@new". Delete the field manually before importing the new field.', array('@name' => $field_name, '@current' => $current_type, '@new' => $new_type)));
}
// Do the complete field validation and rethrow any errors that occur.
try {
$field = $staging_config->get();
field_validate_field($field, TRUE);
}
catch (FieldException $e) {
throw new ConfigValidateException($e->getMessage());
}
}
// Instance validation.
if (strpos($config_name, 'field.instance.') === 0) {
// Do the complete instance validation and rethrow any errors that occur.
try {
$instance = $staging_config->get();
field_validate_instance($instance, FALSE, FALSE);
}
catch (FieldException $e) {
throw new ConfigValidateException($e->getMessage());
}
}
}