You are here

function clients_flickr_clients_service_options in Web Service Clients 7

Same name and namespace in other branches
  1. 6 backends/clients_flickr/clients_flickr.module \clients_flickr_clients_service_options()

Implementation of hook_clients_service_options

File

backends/clients_flickr/clients_flickr.module, line 207
Flickr plugin for Clients module

Code

function clients_flickr_clients_service_options($connection, $wrapper, $wrapper_values, $resource) {
  if ($connection->type != variable_get('clients_flickr_type', 'Flickr')) {
    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'] == 'flickr.photos.search') {
    $form['text'] = array(
      '#type' => 'textfield',
      '#title' => t('Search'),
      '#default_value' => $options_selected['text'],
      '#size' => 40,
      '#maxlength' => 200,
    );
    $form['per_page'] = array(
      '#type' => 'textfield',
      '#title' => t('Per page'),
      '#default_value' => $options_selected['per_page'],
      '#size' => 3,
      '#maxlength' => 3,
    );
    $form['page'] = array(
      '#type' => 'textfield',
      '#title' => t('Page'),
      '#default_value' => $options_selected['page'],
      '#size' => 3,
      '#maxlength' => 3,
    );
    $form['my_images'] = array(
      '#type' => 'checkbox',
      '#title' => t('My images only'),
      '#default_value' => $options_selected['my_images'],
    );

    // and more - http://www.flickr.com/services/api/flickr.photos.search.html
  }
  else {

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