You are here

function wsclient_ui_type in Web service client 7

Data type form.

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

File

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

Code

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

  // 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['properties']['items'][$i])) {
      $form['properties']['items'][$i] = _wsclient_ui_property_row($service, $types);
    }
  }
  $form['properties']['more'] = array(
    '#type' => 'submit',
    '#value' => t('Add more'),
    '#limit_validation_errors' => array(
      array(
        'properties',
      ),
    ),
    '#submit' => array(
      'wsclient_ui_more_submit',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form_state['service'] = $service;
  $form_state['type'] = $type;

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