You are here

function votingapi_views_handler_relationship::options_form in Voting API 6.2

Same name and namespace in other branches
  1. 7.3 views/votingapi_views_handler_relationship.inc \votingapi_views_handler_relationship::options_form()
  2. 7.2 views/votingapi_views_handler_relationship.inc \votingapi_views_handler_relationship::options_form()

Default options form that provides the label widget that all fields should have.

File

views/votingapi_views_handler_relationship.inc, line 50
Provide views handler for votingapi joins.

Class

votingapi_views_handler_relationship
A custom join handler that connects arbitrary base tables to VotingAPI's data.

Code

function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);
  $options['value_types'][''] = t('No filtering');
  $options['tags'][''] = t('No filtering');
  $options['functions'][''] = t('No filtering');
  foreach (votingapi_metadata() as $bin => $bin_data) {
    foreach ($bin_data as $key => $data) {
      $options[$bin][$key] = $data['name'];
    }
  }
  $form['votingapi'] = array(
    '#type' => 'fieldset',
    '#collapsible' => FALSE,
    '#title' => t('Data filters'),
    '#description' => t('For each piece of content, many pieces of voting data may be saved. Use these options to specify exactly which types should be available via this relationship. <strong>Warning!</strong> Leaving any of these filters empty may result in multiple copies of each piece of content being displayed in listings.'),
    '#tree' => TRUE,
  );
  $default = $this->options['votingapi']['value_type'];
  if (!isset($options['value_types'][$default])) {
    $default = '**OTHER**';
  }
  $form['votingapi']['value_type'] = array(
    '#title' => t('Value type'),
    '#type' => 'select',
    '#options' => $options['value_types'],
    '#default_value' => $default,
  );
  $form['votingapi']['value_type']['#options']['**OTHER**'] = t(' -Other- ');
  $form['votingapi']['value_type_other'] = array(
    '#type' => 'textfield',
    '#default_value' => $this->options['votingapi']['value_type'],
    '#process' => array(
      'views_process_dependency',
    ),
    '#dependency' => array(
      'edit-options-votingapi-value-type' => array(
        '**OTHER**',
      ),
    ),
  );
  $default = $this->options['votingapi']['tag'];
  if (!isset($options['tags'][$default])) {
    $default = '**OTHER**';
  }
  $form['votingapi']['tag'] = array(
    '#title' => t('Vote tag'),
    '#type' => 'select',
    '#options' => $options['tags'],
    '#default_value' => $default,
  );
  $form['votingapi']['tag']['#options']['**OTHER**'] = t(' -Other- ');
  $form['votingapi']['tag_other'] = array(
    '#type' => 'textfield',
    '#default_value' => $this->options['votingapi']['tag'],
    '#process' => array(
      'views_process_dependency',
    ),
    '#dependency' => array(
      'edit-options-votingapi-tag' => array(
        '**OTHER**',
      ),
    ),
  );
  if ($this->definition['base'] == 'votingapi_cache') {
    $default = $this->options['votingapi']['function'];
    if (!isset($options['functions'][$default])) {
      $default = '**OTHER**';
    }
    $form['votingapi']['function'] = array(
      '#title' => t('Aggregation function'),
      '#type' => 'select',
      '#options' => $options['functions'],
      '#default_value' => $default,
    );
    $form['votingapi']['function']['#options']['**OTHER**'] = t(' -Other- ');
    $form['votingapi']['function_other'] = array(
      '#type' => 'textfield',
      '#default_value' => $this->options['votingapi']['function'],
      '#process' => array(
        'views_process_dependency',
      ),
      '#dependency' => array(
        'edit-options-votingapi-function' => array(
          '**OTHER**',
        ),
      ),
    );
  }
  else {
    $form['current_user'] = array(
      '#title' => t('Restrict to current user'),
      '#type' => 'checkbox',
      '#return_value' => TRUE,
      '#default_value' => $this->options['current_user'],
    );
  }
}