You are here

function wsclient_tester_data_entry_form in Web service client 7

A mini form element representing the given data type. textfield for most things, but nested fieldsets for complex types.

This recurses through complex types until it hits core types.

Return value

a FAPI form fragment.

1 call to wsclient_tester_data_entry_form()
wsclient_tester_operation_test in wsclient_tester/wsclient_tester.inc
FAPI form used to display the options and the results of calling a web service.

File

wsclient_tester/wsclient_tester.inc, line 192
Utility functions for running the tester UI for web services.

Code

function wsclient_tester_data_entry_form($label, $type, $description, $data, $datatypes) {
  if (isset($datatypes[$type])) {

    // Build a complex type.
    $datatype = $datatypes[$type];
    $element = array(
      '#type' => 'fieldset',
      '#title' => check_plain("{$label} ({$datatype['label']})"),
      '#collapsible' => TRUE,
    );
    foreach ($datatype['property info'] as $field_id => $field_info) {

      // Recurse and get each bit to render its own input element.
      $element[$field_id] = wsclient_tester_data_entry_form($field_id, $field_info['type'], @$field_info['description'], $data[$field_id], $datatypes);
    }
    return $element;
  }
  elseif (preg_match('/^list\\<(.*)\\>$/', $type, $matches)) {

    // Strange notation, type="list<MyType>" means a list of those things.
    // @see wsclient_soap_type_mapper()
    // This becomes a numerically indexed array.
    // Present it in the form as a nested list.
    $actual_type = $matches[1];
    $element = array(
      '#type' => 'fieldset',
      '#title' => t("List of %label (%type)", array(
        '%label' => $label,
        '%type' => $type,
      )),
      '#collapsible' => TRUE,
    );
    for ($field_id = 0; $field_id < 3; $field_id++) {

      // Recurse and get each bit to render its own input element
      $element[$field_id] = wsclient_tester_data_entry_form($field_id, $actual_type, NULL, $data[$field_id], $datatypes);
      $element[$field_id]['#collapsed'] = TRUE;
    }
    return $element;
  }
  elseif ($type == 'text_formatted') {
    return array(
      '#type' => 'textarea',
      '#title' => t("%label (%type)", array(
        '%label' => $label,
        '%type' => $type,
      )),
      '#default_value' => $data,
      '#description' => $description,
    );
  }
  elseif ($type == 'boolean') {
    return array(
      '#type' => 'select',
      '#title' => t("%label (%type)", array(
        '%label' => $label,
        '%type' => $type,
      )),
      '#default_value' => $data,
      // Defining false first so it's the default when setting up a form.
      '#options' => array(
        'false' => 'false',
        'true' => 'true',
      ),
      '#description' => $description,
    );
  }
  else {

    // A textfield will normally do for any other primitives.
    return array(
      '#type' => 'textfield',
      '#title' => t("%label (%type)", array(
        '%label' => $label,
        '%type' => $type,
      )),
      '#default_value' => $data,
      '#size' => 20,
      '#description' => $description,
    );
  }
}