function clients_connection_test_form in Web Service Clients 7.3
Same name and namespace in other branches
- 6.2 clients.connection.admin.inc \clients_connection_test_form()
- 7 clients.connection.admin.inc \clients_connection_test_form()
- 7.2 clients.connection.admin.inc \clients_connection_test_form()
Form to test a connection.
Parameters
$connection: A loaded connection.
1 string reference to 'clients_connection_test_form'
- ClientsConnectionEntityUIController::hook_menu in includes/
clients.ui.inc - Provides definitions for implementing hook_menu().
File
- includes/
clients.connection.admin.inc, line 340 - clients.connection.admin.inc Page callbacks relating to client connection admin.
Code
function clients_connection_test_form($form, &$form_state, $connection) {
$type_definition = clients_get_connection_types($connection->type);
$form['#connection'] = $connection;
$form['connection'] = array(
'#type' => 'fieldset',
'#title' => t('Connection details'),
);
$items[] = t('Type') . ': ' . $type_definition['label'];
$items[] = t('Name') . ': ' . check_plain($connection->name);
$items[] = t('Endpoint') . ': ' . $connection->endpoint;
$resources = clients_resource_load_for_connection($connection->name);
$resource_labels = array();
foreach ($resources as $resource) {
$uri = $resource
->uri();
$resource_labels[] = l($resource->label, $uri['path']);
}
$items[] = t('Resources') . ': ' . implode(', ', $resource_labels);
$form['connection']['details'] = array(
'#markup' => theme('item_list', array(
'items' => $items,
)),
);
// Buttons.
// ??? These are themed into a vertical list with the description text alongside each one.
$form['buttons'] = array(
'#tree' => TRUE,
);
// Allow applications that use this connection to add their own test buttons.
if (empty($type_definition['tests'])) {
$type_definition['tests'] = array();
}
drupal_alter('client_connection_tests', $type_definition['tests'], $connection);
// Store the type definition with the altered tests in the form for the
// validate and submit handlers.
$form['#connection_type'] = $type_definition;
if (!empty($type_definition['tests'])) {
foreach ($type_definition['tests'] as $test_name => $test_class) {
$test_handler = new $test_class();
// Get the labels from the test handler.
$labels = $test_handler
->testLabels();
// Build a template form element to pass in to the test handler.
$element = array(
'#type' => 'fieldset',
'#title' => $labels['label'],
);
$element['description'] = array(
'#prefix' => '<div>',
'#markup' => $labels['description'],
'#suffix' => '</div>',
);
$element['params'] = array();
$element['submit'] = array(
'#type' => 'button',
'#value' => $labels['button'],
'#name' => $test_name,
'#ajax' => array(
'event' => 'click',
'callback' => 'clients_connection_test_js',
'wrapper' => $test_name . '-results',
'name' => $test_name,
),
'#limit_validation_errors' => array(
array(
'buttons',
$test_name,
),
),
);
// AJAX wrapper for test results.
$element['results'] = array(
'#prefix' => '<div id="' . $test_name . '-results">',
'#suffix' => '</div>',
);
if (method_exists($test_handler, 'testForm')) {
$form['buttons'][$test_name] = $test_handler
->testForm($element);
}
else {
$form['buttons'][$test_name] = $element;
}
}
}
else {
// TODO: show a message if no buttons at all!?
}
return $form;
}