You are here

function clients_drupal_clients_service_options in Web Service Clients 6

Same name and namespace in other branches
  1. 7 backends/clients_drupal/clients_drupal.module \clients_drupal_clients_service_options()

Implementation of hook_clients_service_options

File

backends/clients_drupal/clients_drupal.module, line 274
Drupal Services plugin for Clients module @author Django Beatty - adub

Code

function clients_drupal_clients_service_options($connection, $wrapper, $wrapper_values, $resource) {
  if ($connection->type != variable_get('clients_drupal_type', 'Drupal Services')) {
    return;
  }
  $form = array();
  $connection = clients_connection_load((int) $connection->cid);
  $methods = array_map('trim', explode("\n", trim($connection->configuration['methods_enabled'])));
  $methods = array_combine($methods, $methods);
  $options_selected = isset($wrapper_values['options']) ? $wrapper_values['options'] : (isset($resource->rid) ? $resource->configuration['options'] : array());

  // if we change connection and method doesn't exist, reset
  if (!in_array($options_selected['method'], $methods)) {
    $options_selected['method'] = key($methods);
  }
  $form['method'] = array(
    '#type' => 'select',
    '#title' => t('Method'),
    '#default_value' => $options_selected['method'],
    '#options' => $methods,
    '#description' => t('Choose method'),
    '#required' => TRUE,
    '#ahah' => array(
      'path' => ahah_helper_path(array(
        $wrapper,
      )),
      'wrapper' => $wrapper,
      'method' => 'replace',
      'effect' => 'fade',
    ),
  );
  if ($options_selected['method'] == 'views.get') {
    $views = array_map('trim', explode("\n", trim($connection->configuration['views_enabled'])));
    $views = array_combine($views, $views);
    $form['view'] = array(
      '#type' => 'select',
      '#title' => t('View'),
      '#default_value' => $options_selected['view'],
      '#options' => $views,
      '#description' => t('Choose view'),
    );
    $form['arguments']['first'] = array(
      '#type' => 'textfield',
      '#title' => t('Argument'),
      '#default_value' => $options_selected['arguments']['first'],
      '#size' => 10,
      '#maxlength' => 30,
    );
    $form['offset'] = array(
      '#type' => 'textfield',
      '#title' => t('Offset'),
      '#default_value' => $options_selected['offset'],
      '#size' => 3,
      '#maxlength' => 4,
    );
    $form['limit'] = array(
      '#type' => 'textfield',
      '#title' => t('Limit'),
      '#default_value' => $options_selected['limit'],
      '#size' => 3,
      '#maxlength' => 4,
    );
  }
  else {

    /**
     * @todo some 'method not supported' handling
     */
  }
  return $form;
}