You are here

function clients_connection_add in Web Service Clients 7

Same name and namespace in other branches
  1. 6.2 clients.connection.admin.inc \clients_connection_add()
  2. 7.2 clients.connection.admin.inc \clients_connection_add()

Form builder for adding 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

$type: The machine name of a connection type.

See also

clients_connection_form_submit()

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

File

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

Code

function clients_connection_add(&$form_state, $type) {
  $form = array();
  $connection_types = clients_get_connection_types();

  //dsm($connection_types);
  if (isset($connection_types[$type])) {
    $class = 'clients_connection_' . $type;

    // When 5.3 is the norm, we can do:

    //$form = $class::connectionSettingsForm($form_state);
    $form['#connection_type'] = $type;
    $form['#connection_class'] = $class;
    $form['type'] = array(
      '#type' => 'textfield',
      '#title' => t('Connection type'),
      '#description' => t('The type of connection to create. May not be changed.'),
      '#value' => $type,
      '#size' => 50,
      '#disabled' => TRUE,
    );

    // When PHP 5.3 is the norm, we can just say $class::$method().
    $form += call_user_func(array(
      $class,
      'connectionSettingsForm',
    ), $form_state, $type);
    $form['buttons']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Add connection'),
    );

    // Add our submit handler common with the edit form.
    $form['#submit'] = array(
      'clients_connection_form_submit',
    );
    return $form;
  }
  else {
    return drupal_not_found();
  }
}