function key_config_form_validate in Key 7.3
Same name and namespace in other branches
- 7.2 includes/key.admin.inc \key_config_form_validate()
Form validate handler for key_config_form().
File
- includes/
key.admin.inc, line 285 - Administrative functionality for managing key configurations.
Code
function key_config_form_validate($form, &$form_state) {
if (!$form_state['submitted']) {
return;
}
$plugin_types = _key_get_plugin_types();
$key_type = key_get_plugin('key_type', $form_state['values']['key_type']);
$key_provider = key_get_plugin('key_provider', $form_state['values']['key_provider']);
$key_input = key_get_plugin('key_input', $form_state['values']['key_input']);
// Update the key configuration in form state storage.
foreach (array_keys($form_state['storage']['key_config']) as $id) {
if (isset($form_state['values'][$id])) {
$form_state['storage']['key_config'][$id] = $form_state['values'][$id];
}
}
// Make sure each plugin settings field is an array.
foreach (_key_get_plugin_types() as $type) {
if (empty($form_state['values'][$type . '_settings'])) {
$form_state['values'][$type . '_settings'] = array();
}
}
$processed_values = array(
'submitted' => NULL,
'processed_submitted' => NULL,
);
foreach ($plugin_types as $type) {
$plugin = ${$type};
$plugin_form_state = _key_create_plugin_form_state($type, $form_state);
// Special behavior for the Key Input plugin.
if ($type == 'key_input') {
// If the provider accepts a key value.
if ($key_provider['key value']['accepted']) {
$process_value_function = ctools_plugin_get_function($key_input, 'process submitted key value');
$processed_values = $process_value_function($plugin_form_state);
}
}
if ($validate_function = ctools_plugin_get_function($plugin, 'validate configuration form')) {
$validate_function($form, $plugin_form_state);
}
$form_state['values'][$type . '_settings'] = $plugin_form_state['values'];
_key_move_form_state_storage($plugin_form_state, $form_state);
}
// Store the submitted and processed key values in form state.
$form_state['storage']['key_value']['submitted'] = $processed_values['submitted'];
$form_state['storage']['key_value']['processed_submitted'] = $processed_values['processed_submitted'];
// Allow the Key Type plugin to validate the key value. Use the processed
// key value if there is one. Otherwise, retrieve the key value using the
// key provider.
if ($validate_function = ctools_plugin_get_function($key_type, 'validate key value')) {
if (!empty($processed_values['processed_submitted'])) {
$key_value = $processed_values['processed_submitted'];
}
else {
// Create a temporary key configuration to retrieve the key value.
$temp_key = $form_state['values'];
$key_value = key_get_key_value($temp_key);
}
$plugin_form_state = _key_create_plugin_form_state('key_type', $form_state);
$validate_function($form, $plugin_form_state, $key_value);
$form_state['values']['key_type_settings'] = $plugin_form_state['values'];
_key_move_form_state_storage($plugin_form_state, $form_state);
}
}