You are here

function clients_connection_test_form in Web Service Clients 7

Same name and namespace in other branches
  1. 6.2 clients.connection.admin.inc \clients_connection_test_form()
  2. 7.3 includes/clients.connection.admin.inc \clients_connection_test_form()
  3. 7.2 clients.connection.admin.inc \clients_connection_test_form()

Page callback to test a connection.

Parameters

$cid: The id of a connection.

1 string reference to 'clients_connection_test_form'
clients_menu in ./clients.module
Implementation of hook_menu()

File

./clients.connection.admin.inc, line 247
clients.connection.admin.inc Page callbacks relating to client connection admin.

Code

function clients_connection_test_form(&$form_state, $cid) {
  $connection = clients_get_connection($cid);
  $form['#connection'] = $connection;
  $form['connection'] = array(
    '#type' => 'fieldset',
    '#title' => t('Connection details'),
  );
  $items[] = t('Type') . ': ' . $connection->type;
  $items[] = t('Name') . ': ' . check_plain($connection->name);
  $items[] = t('Endpoint') . ': ' . $connection->endpoint;
  $form['connection']['details'] = array(
    '#value' => theme('item_list', $items),
  );

  // Buttons. These are themed into a vertical list with the description text alongside each one.
  $form['buttons'] = array(
    //'#theme' => 'uprpc_manual_form_button',
    '#tree' => TRUE,
  );

  // Get the core buttons provided by the connection class.
  $buttons = $connection
    ->getTestOperations($form_state, $cid);

  // Allow applications that use this connection to add their own test buttons.
  drupal_alter('client_connection_test_buttons', $buttons, $form_state, $cid);

  // Some processing of the buttons to simplify the method of specifying them.
  // see ClientsServicesDrupal_5::getTestOperations for an example of how this works.
  foreach ($buttons as $key => $button) {

    // If the button is just a plain button, wrap it in a fieldset.
    // This allows you to return just a button if there are no extra form elements.
    if ($button['#type'] == 'submit') {
      $form['buttons'][$key] = array(
        '#type' => 'fieldset',
      );
      $form['buttons'][$key]['button'] = $button;
    }
    else {
      $form['buttons'][$key] = $button;
    }

    // In all cases, show the description for the action.

    /*
    $form['buttons'][$key]['description'] = array(
      '#value' => $form['buttons'][$key]['button']['#description'],
      '#weight' => -10,

    );
    */
    $form['buttons'][$key]['#description'] = $form['buttons'][$key]['button']['#description'];
    $form['buttons'][$key]['#tree'] = TRUE;
    $form['buttons'][$key]['button']['#key'] = $key;
  }

  // TODO: allow applications to add buttons to this connection.
  // Show the results that the button handler returned.
  foreach (array_keys($form['buttons']) as $button_id) {

    // If there is a key in the form storage with the same ID as a button,
    // the it is the result of a previous manual test.
    if (isset($form_state['storage'][$button_id])) {
      $form['buttons'][$button_id]['results'] = array(
        '#type' => 'fieldset',
        '#title' => t('Results'),
        '#collapsible' => TRUE,
      );
      $title = $form['buttons'][$button_id]['#value'];
      $data = check_plain(print_r($form_state['storage'][$button_id], TRUE));
      $form['buttons'][$button_id]['results'][$button_id] = array(
        '#type' => 'markup',
        '#value' => "<h3>{$title}</h3>" . "<pre>{$data}</pre>",
      );

      // Clear the storage so it doesn't just accumulate.
      unset($form_state['storage'][$button_id]);
    }
  }

  // TODO: show a message if no buttons at all!
  return $form;
}