1 views_handler_filter_in_operator.inc views_handler_filter_in_operator::value_form(&$form, &$form_state)

Options form subform for setting options.

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

Overrides views_handler_filter::value_form

See also

options_form()

File

core/modules/views/handlers/views_handler_filter_in_operator.inc, line 161
Definition of views_handler_filter_in_operator.

Class

views_handler_filter_in_operator
Simple filter to handle matching of multiple options selectable via checkboxes

Code

function value_form(&$form, &$form_state) {
  $form['value'] = array();
  $options = array();

  if (empty($form_state['exposed'])) {
    // Add a select all option to the value form.
    $options = array('all' => t('Select all'));
  }

  $this->get_value_options();
  $options += $this->value_options;
  $default_value = (array) $this->value;

  $which = 'all';
  if (!empty($form['operator'])) {
    $source = ':input[name="options[operator]"]';
  }
  if (!empty($form_state['exposed'])) {
    $identifier = $this->options['expose']['identifier'];

    if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator_id'])) {
      // exposed and locked.
      $which = in_array($this->operator, $this->operator_values(1)) ? 'value' : 'none';
    }
    else {
      $source = ':input[name="' . $this->options['expose']['operator_id'] . '"]';
    }

    if (!empty($this->options['expose']['reduce'])) {
      $options = $this->reduce_value_options();

      if (!empty($this->options['expose']['multiple']) && empty($this->options['expose']['required'])) {
        $default_value = array();
      }
    }

    if (empty($this->options['expose']['multiple'])) {
      if (empty($this->options['expose']['required']) && (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);
      }
    }
  }

  if ($which == 'all' || $which == 'value') {
    $form['value'] = array(
      '#type' => $this->value_form_type,
      '#title' => $this->value_title,
      '#options' => $options,
      '#default_value' => $default_value,
      // These are only valid for 'select' type, but do no harm to checkboxes.
      '#multiple' => TRUE,
      '#size' => count($options) > 8 ? 8 : count($options),
    );
    if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
      $form_state['input'][$identifier] = $default_value;
    }

    if ($which == 'all') {
      if (empty($form_state['exposed']) && (in_array($this->value_form_type, array('checkbox', 'checkboxes', 'radios', 'select')))) {
        $form['value']['#prefix'] = '<div id="edit-options-value-wrapper">';
        $form['value']['#suffix'] = '</div>';
      }
      // Setup #states for all operators with one value.
      foreach ($this->operator_values(1) as $operator) {
        $form['value']['#states']['visible'][] = array(
          $source => array('value' => $operator),
        );
      }
    }
  }
}