You are here

function menu_references_filter_handler::value_form in Menu Reference 7

Options form subform for setting options.

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

Overrides views_handler_filter_in_operator::value_form

See also

options_form()

File

views/handlers/menu_references_filter_handler.inc, line 74
Views filter handler

Class

menu_references_filter_handler
@file Views filter handler

Code

function value_form(&$form, &$form_state) {
  $form['value'] = array();
  $options = array();
  $this
    ->get_value_options();
  $options += $this->value_options;
  $default_value = (array) $this->value;
  $which = 'all';
  if (!empty($form['operator'])) {
    $source = $form['operator']['#type'] == 'radios' ? 'radio:options[operator]' : 'edit-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 = 'edit-' . drupal_html_id($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') {
    if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
      $default_value = !empty($default_value) ? $default_value : 'All';
      $form_state['input'][$identifier] = $default_value;
    }
    $form['value'] = array(
      '#type' => 'select',
      '#title' => $this->value_title,
      '#multiple' => TRUE,
      '#size' => 10,
      '#options' => $options,
      '#default_value' => $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>';
      }
      $form['value']['#dependency'] = array(
        $source => $this
          ->operator_values(1),
      );
    }
  }
}