You are here

function clients_connection_form in Web Service Clients 7.2

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

Form builder for editing a connection.

Gets the class of the connection from the data in the form and calls the connectionSettingsForm() method on the class to build the form. This allows different elements for different connection types.

Parameters

$connection: A connection object.

See also

clients_connection_form_validate()

clients_connection_form_submit()

2 string references to 'clients_connection_form'
clients_connection_add in ./clients.connection.admin.inc
Menu callback for adding a new connection.
clients_menu in ./clients.module
Implements hook_menu()

File

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

Code

function clients_connection_form($form, &$form_state, $connection) {
  $form = array();

  // Save on repeated isset()s.
  if (!isset($connection->new)) {
    $connection->new = FALSE;
  }
  $type = $connection->type;
  $class = 'clients_connection_' . $type;
  $form['old_connection'] = array(
    '#type' => 'value',
    '#value' => $connection,
  );

  //dsm($connection);
  $form['type'] = array(
    '#type' => 'textfield',
    '#title' => t('Connection type'),
    '#description' => t('The type of this connection. May not be changed.'),
    '#value' => $connection->type,
    '#size' => 50,
    '#disabled' => TRUE,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Connection machine name'),
    '#default_value' => $connection->name,
    '#size' => 50,
    '#maxlength' => 100,
    '#description' => t('The connection name must contain only lowercase letters, numbers, and underscores. It must be unique.'),
    '#required' => TRUE,
  );
  if ($connection->name) {
    $form['name']['#description'] .= '<br /><strong>' . t('Warning: Changing the name of an existing connection may affect any data you have stored based on that connection.') . '</strong>';
  }
  $form['endpoint'] = array(
    '#type' => 'textfield',
    '#title' => t('Connection endpoint'),
    '#default_value' => $connection->new ? '' : $connection->endpoint,
    '#size' => 100,
    '#maxlength' => 100,
    '#description' => t('Remote service URL e.g. http://mysite.com/services/endpoint'),
    '#required' => TRUE,
  );

  // Container for all form elements whose values should be serialized to the
  // configuration array.
  // Not a fieldset by default, but connection classes may choose to do this.
  $form['configuration'] = array(
    '#tree' => TRUE,
  );
  $form['#connection_type'] = $type;
  $form['#connection_class'] = $class;

  // Allow the connection class to make additions to the form. We don't use
  // the node_form() pattern because typically a connection class will want to
  // change the 'endpoint' element to add custom help text.
  $form = $connection
    ->connectionSettingsForm($form, $form_state);
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save connection'),
  );
  return $form;
}