You are here

function wsclient_ui_operation in Web service client 7

Operation form.

1 string reference to 'wsclient_ui_operation'
WSClientUIController::hook_menu in wsclient_ui/wsclient_ui.inc
Customizes menu items.

File

wsclient_ui/wsclient_ui.inc, line 551
WSClient UI - implements service description management and configuration screens.

Code

function wsclient_ui_operation($form, &$form_state, $service, $operation, $op = 'edit') {
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Label'),
    '#default_value' => isset($operation['label']) ? $operation['label'] : '',
    '#required' => TRUE,
    '#description' => t('The human-readable name of the operation.'),
    '#weight' => -10,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => isset($operation['name']) ? $operation['name'] : '',
    '#required' => TRUE,
    '#description' => t('The machine-readable name of this operation is used internally to identify the operation.'),
    '#element_validate' => array(
      'wsclient_ui_operation_name_validate',
    ),
    '#weight' => -10,
  );
  $form['parameters'] = array(
    '#tree' => TRUE,
    '#element_validate' => array(
      'wsclient_ui_validate_parameters',
    ),
    '#theme' => 'wsclient_ui_parameter_form',
    '#title' => t('Parameters'),
    '#description' => t('Specify the parameters for the operation. For each parameter you have to specify a certain data type and a unique name containing only alphanumeric characters and underscores. You can also specify a default value for the parameter, if the parameter is required, and if null values are allowed.'),
  );
  $weight = 0;
  $types = wsclient_ui_types(TRUE);
  if (isset($operation['parameter'])) {
    foreach ($operation['parameter'] as $name => $info) {
      $form['parameters']['items'][$name] = _wsclient_ui_parameter_row($service, $types, $name, $info);
      $form['parameters']['items'][$name]['weight']['#default_value'] = $weight++;
    }
  }

  // Always add three empty lines.
  $form_state['more'] = isset($form_state['more']) ? $form_state['more'] : 3;
  for ($i = 0; $i < $form_state['more']; $i++) {
    if (!isset($form['parameters']['items'][$i])) {
      $form['parameters']['items'][$i] = _wsclient_ui_parameter_row($service, $types);
      $form['parameters']['items'][$i]['weight']['#default_value'] = $weight++;
    }
  }
  $form['parameters']['more'] = array(
    '#type' => 'submit',
    '#value' => t('Add more'),
    '#limit_validation_errors' => array(
      array(
        'parameters',
      ),
    ),
    '#submit' => array(
      'wsclient_ui_more_submit',
    ),
  );

  // SOAP 1.2 etc may also require additional headers.
  if ($service->type == 'soap 1.2') {
    $form['headers'] = array(
      '#tree' => TRUE,
      '#theme' => 'wsclient_ui_header_form',
      '#title' => t('Soap 1.2 Headers'),
      '#description' => t('Some services may also require specific headers to be set, such as "To" for their internal routing, or the SOAP_1_2 "mustunderstand" flag.'),
    );
    $weight = 0;
    $types = wsclient_ui_types(TRUE);
    if (isset($operation['header'])) {
      foreach ($operation['header'] as $name => $info) {
        $form['headers']['items'][$name] = _wsclient_ui_header_row($info);
        $form['headers']['items'][$name]['weight']['#default_value'] = $weight++;
      }
    }

    // Always add an empty line.
    $form['headers']['items'][$i] = _wsclient_ui_header_row(array());
    $form['headers']['items'][$i]['weight']['#default_value'] = $weight++;
  }

  // Exclude the hidden data type for result types.
  unset($types['hidden']);
  $result_type = 0;
  $multiple = FALSE;
  if (isset($operation['result']['type'])) {
    $result_type = wsclient_map_type($service->name, $service
      ->dataTypes(), $operation['result']['type']);
    if (strpos($result_type, 'list<') === 0) {
      $multiple = TRUE;

      // Cut off the 'list<>' indicator.
      $result_type = substr($result_type, 5, -1);
    }
  }
  $form['result_type'] = array(
    '#type' => 'select',
    '#title' => t('Result type'),
    '#options' => array(
      0 => '--',
    ) + $types,
    '#default_value' => $result_type,
    '#description' => t('The result data type returned by the service'),
  );
  $form['result_multiple'] = array(
    '#type' => 'checkbox',
    '#title' => t('Multiple result'),
    '#default_value' => $multiple,
    '#description' => t('If checked, the result variable is a list containing multiple elements of the result type.'),
  );
  $form['result_label'] = array(
    '#type' => 'textfield',
    '#title' => t('Result label'),
    '#default_value' => isset($operation['result']['label']) ? $operation['result']['label'] : '',
    '#description' => t('The human-readable name of the result variable returned by the service.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form_state['service'] = $service;
  $form_state['operation'] = $operation;

  // Allow the endpoint to make alterations to the form.
  $form_state['form'] = 'operation';
  $service
    ->endpoint()
    ->formAlter($form, $form_state);
  $form['#submit'][] = 'wsclient_ui_operation_submit';
  return $form;
}