You are here

public function views_handler_filter_numeric::value_form in Views (for Drupal 7) 7.3

Same name and namespace in other branches
  1. 6.3 handlers/views_handler_filter_numeric.inc \views_handler_filter_numeric::value_form()
  2. 6.2 handlers/views_handler_filter_numeric.inc \views_handler_filter_numeric::value_form()

Provide a simple textfield for equality

Overrides views_handler_filter::value_form

1 call to views_handler_filter_numeric::value_form()
views_handler_filter_date::value_form in handlers/views_handler_filter_date.inc
Add a type selector to the value form.
1 method overrides views_handler_filter_numeric::value_form()
views_handler_filter_date::value_form in handlers/views_handler_filter_date.inc
Add a type selector to the value form.

File

handlers/views_handler_filter_numeric.inc, line 160
Definition of views_handler_filter_numeric.

Class

views_handler_filter_numeric
Simple filter to handle greater than/less than filters

Code

public function value_form(&$form, &$form_state) {
  $form['value']['#tree'] = TRUE;

  // We have to make some choices when creating this as an exposed
  // filter form. For example, if the operator is locked and thus
  // not rendered, we can't render dependencies; instead we only
  // render the form items we need.
  $which = 'all';
  $limit_operators = !empty($this->options['expose']['limit_operators']) && count($this->options['expose']['available_operators']) > 0;
  $use_value = FALSE;
  $use_minmax = FALSE;
  if (!empty($form['operator'])) {
    $source = $form['operator']['#type'] == 'radios' ? 'radio:options[operator]' : 'edit-options-operator';
  }
  if (!empty($form_state['exposed'])) {
    $operator_values_with_1_values = $this
      ->operator_values(1);
    $operator_values_with_2_values = $this
      ->operator_values(2);
    if ($limit_operators) {

      // If limit operators is enabled, check that at least one operator
      // with two values is enabled to display the min max widgets
      foreach ($operator_values_with_2_values as $operator) {
        if (isset($this->options['expose']['available_operators'][$operator])) {
          $use_minmax = TRUE;
          break;
        }
      }

      // the same for operators with one value
      foreach ($operator_values_with_1_values as $operator) {
        if (isset($this->options['expose']['available_operators'][$operator])) {
          $use_value = TRUE;
          break;
        }
      }
    }
    else {
      $use_minmax = $use_value = TRUE;
    }
    $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, $operator_values_with_2_values) ? 'minmax' : 'value';
    }
    else {
      $source = 'edit-' . drupal_html_id($this->options['expose']['operator_id']);
    }
  }
  else {
    $use_minmax = $use_value = TRUE;
  }
  if ($use_value) {
    if ($which == 'all') {
      $form['value']['value'] = array(
        '#type' => 'textfield',
        '#title' => empty($form_state['exposed']) ? t('Value') : '',
        '#size' => 30,
        '#default_value' => $this->value['value'],
        '#dependency' => array(
          $source => $this
            ->operator_values(1),
        ),
      );
      if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['value'])) {
        $form_state['input'][$identifier]['value'] = $this->value['value'];
      }
    }
    elseif ($which == 'value') {

      // When exposed we drop the value-value and just do value if
      // the operator is locked.
      $form['value'] = array(
        '#type' => 'textfield',
        '#title' => empty($form_state['exposed']) ? t('Value') : '',
        '#size' => 30,
        '#default_value' => $this->value['value'],
      );
      if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
        $form_state['input'][$identifier] = $this->value['value'];
      }
    }
  }
  if ($which == 'all' || $which == 'minmax') {
    if ($use_minmax) {
      $form['value']['min'] = array(
        '#type' => 'textfield',
        '#title' => empty($form_state['exposed']) ? t('Min') : '',
        '#size' => 30,
        '#default_value' => $this->value['min'],
      );
      $form['value']['max'] = array(
        '#type' => 'textfield',
        '#title' => empty($form_state['exposed']) ? t('And max') : t('And'),
        '#size' => 30,
        '#default_value' => $this->value['max'],
      );
      if ($which == 'all') {
        $dependency = array(
          '#dependency' => array(
            $source => $this
              ->operator_values(2),
          ),
        );
        $form['value']['min'] += $dependency;
        $form['value']['max'] += $dependency;
      }
    }
    if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['min']) && $use_minmax) {
      $form_state['input'][$identifier]['min'] = $this->value['min'];
    }
    if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['max']) && $use_minmax) {
      $form_state['input'][$identifier]['max'] = $this->value['max'];
    }
    if (!isset($form['value'])) {

      // Ensure there is something in the 'value'.
      $form['value'] = array(
        '#type' => 'value',
        '#value' => NULL,
      );
    }
  }
}