function geocoder_field_field_config_edit_form_validate in Geocoder 8.2
Same name and namespace in other branches
- 8.3 modules/geocoder_field/geocoder_field.module \geocoder_field_field_config_edit_form_validate()
Provides an additional form validation callback for 'field_config_edit_form'.
Parameters
array $form: A form API form.
\Drupal\Core\Form\FormStateInterface $form_state: The form state object.
1 string reference to 'geocoder_field_field_config_edit_form_validate'
- geocoder_field_form_field_config_edit_form_alter in modules/
geocoder_field/ geocoder_field.module - Implements hook_form_FORM_ID_alter().
File
- modules/
geocoder_field/ geocoder_field.module, line 109 - Geocoder Field module.
Code
function geocoder_field_field_config_edit_form_validate(array $form, FormStateInterface $form_state) {
// Don't store any settings for this field if it's not configured to use
// geocoding.
$third_party_settings = $form_state
->getValue('third_party_settings');
if ($third_party_settings['geocoder_field']['method'] == 'none') {
unset($third_party_settings['geocoder_field']);
$form_state
->setValue('third_party_settings', $third_party_settings);
return;
}
// Clean-up and normalize the plugin list.
$trail = [
'third_party_settings',
'geocoder_field',
'plugins',
];
$plugins = array_keys(array_filter($form_state
->getValue($trail), function ($item) {
return (bool) $item['checked'];
}));
$form_state
->setValue($trail, $plugins);
// Give a chance to the geocoder field plugin to perform its own validation.
$geocoder_data = (new FormState())
->setValues($form_state
->getValue([
'third_party_settings',
'geocoder_field',
]));
$trail = [
'third_party_settings',
'geocoder_field',
'field_plugin',
];
/** @var \Drupal\geocoder_field\GeocoderFieldPluginInterface $field_plugin */
$field_plugin = $form_state
->getValue($trail);
$field_plugin
->validateSettingsForm($form, $geocoder_data);
// Update the $form_state with the $geocoder_data possibly altered in the
// validateSettingsForm method.
$form_state
->setValue([
'third_party_settings',
'geocoder_field',
], $geocoder_data
->getValues());
// Copy back any error.
foreach ($geocoder_data
->getErrors() as $name => $error) {
$form_state
->setErrorByName($name, $error);
}
// Unset temporary field plugin value.
$form_state
->unsetValue($trail);
}