You are here

function views_handler_filter_tag_font_tid::value_form in @font-your-face 7

Same name and namespace in other branches
  1. 6.2 views/views_handler_filter_tag_font_tid.inc \views_handler_filter_tag_font_tid::value_form()
  2. 7.2 modules/fontyourface_ui/views/views_handler_filter_tag_font_tid.inc \views_handler_filter_tag_font_tid::value_form()

Options form subform for setting options.

This should be overridden by all child classes and it must define $form['value'].

Overrides views_handler_filter_many_to_one::value_form

See also

options_form()

File

views/views_handler_filter_tag_font_tid.inc, line 41
Views handler.

Class

views_handler_filter_tag_font_tid
Filter by tag id. Largely copied from views_handler_filter_term_node_tid.inc

Code

function value_form(&$form, &$form_state) {
  if ($this->options['type'] == 'textfield') {
    $default = '';
    if ($this->value) {
      $result = db_select('fontyourface_tag', 't')
        ->condition('t.tid', $this->value, 'IN')
        ->execute();
      foreach ($result as $tag) {
        if ($default) {
          $default .= ', ';
        }

        // if
        $default .= $tag->name;
      }

      // foreach
    }

    // if
    $form['value'] = array(
      '#title' => t('Select tags'),
      '#type' => 'textfield',
      '#default_value' => $default,
    );
  }
  else {
    $options = array();
    $result = db_query("SELECT t.* FROM {fontyourface_tag} t ORDER BY t.name");
    while ($tag = $result
      ->fetchObject()) {
      $options[$tag->tid] = $tag->name;
    }

    // while
    $default_value = (array) $this->value;
    if (!empty($form_state['exposed'])) {
      $identifier = $this->options['expose']['identifier'];
      if (!empty($this->options['expose']['reduce'])) {
        $options = $this
          ->reduce_value_options($options);
        if (empty($this->options['expose']['single']) && !empty($this->options['expose']['optional'])) {
          $default_value = array();
        }

        // if
      }

      // if
      if (!empty($this->options['expose']['single'])) {
        if (!empty($this->options['expose']['optional']) && (empty($default_value) || !empty($this->options['expose']['reduce']))) {
          $default_value = 'All';
        }
        elseif (empty($default_value)) {
          $keys = array_keys($options);
          $default_value = array_shift($keys);
        }
        else {
          $copy = $default_value;
          $default_value = array_shift($copy);
        }

        // else
      }

      // if
    }

    // if
    $form['value'] = array(
      '#type' => 'select',
      '#title' => t('Select tags'),
      '#multiple' => TRUE,
      '#options' => $options,
      '#size' => min(9, count($options)),
      '#default_value' => $default_value,
    );
    if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
      $form_state['input'][$identifier] = $default_value;
    }

    // if
  }

  // else
  if (empty($form_state['exposed'])) {
    $this->helper
      ->options_form($form, $form_state);
  }

  // if
}