function clients_connection_form_submit in Web Service Clients 7.3
Same name and namespace in other branches
- 6.2 clients.connection.admin.inc \clients_connection_form_submit()
- 7 clients.connection.admin.inc \clients_connection_form_submit()
- 7.2 clients.connection.admin.inc \clients_connection_form_submit()
Form submit handler for the connection form.
Gets the class of the connection from the data in the form and calls the connectionSettingsForm_submit() method on the class. This allows different behaviour for different connection types, while saving is handled here.
See also
clients_connection_base::connectionSettingsForm_submit()
File
- includes/
clients.connection.admin.inc, line 259 - clients.connection.admin.inc Page callbacks relating to client connection admin.
Code
function clients_connection_form_submit($form, &$form_state) {
// If the delete button was clicked, redirect to the delete form and quit.
if ($form_state['triggering_element']['#name'] == 'delete') {
$form_state['redirect'] = 'admin/structure/clients/connections/manage/' . $form['#connection']->name . '/delete';
return;
}
// Build the entity from the form values.
// Note that this will place a 'credentials' propery on it, from the form
// fieldset, which will not be saved because there is no schema for it.
$connection = entity_ui_form_submit_build_entity($form, $form_state);
ctools_include('plugins');
// Set the credentials storage plugin id on the connection.
$connection->configuration['credentials_storage'] = $form_state['values']['credentials']['credentials_storage'];
// Call connectionSettingsForm_submit() on the connection handler.
// This allows treatment of form values particular to the connection type.
// The base class also handles restoring the password from credentials storage
// to the connection if the form element was left blank.
$connection
->connectionSettingsForm_submit($form, $form_state);
// Call the credentials storage plugin to handle saving the credentials.
$credentials_storage_plugin = $connection
->get_credentials_storage_plugin();
$credentials_storage_plugin
->credentialsSave($connection);
// If the credentials storage method has changed, delete the old storage.
// We do this last, as the copying of the password relies on the old
// credentials still existing.
if (isset($form['#connection_credentials_storage']) && $form['#connection_credentials_storage'] != $form_state['values']['credentials']['credentials_storage']) {
// Delete the credentials from the old storage.
// Get the old plugin for $form['#connection_credentials_storage'].
$old_credentials_storage_plugin = $connection
->get_credentials_storage_plugin($form['#connection_credentials_storage']);
// Let the old plugin delete its storage.
$old_credentials_storage_plugin
->credentialsDelete($connection);
}
// Save and go back.
$connection
->save();
drupal_set_message(t('Connection saved.'));
$form_state['redirect'] = 'admin/structure/clients/connections';
}