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

Provide a simple textfield for equality

Overrides views_handler_filter::value_form

File

core/modules/views/handlers/views_handler_filter_string.inc, line 182
Definition of views_handler_filter_string.

Class

views_handler_filter_string
Basic textfield filter to handle string filtering commands including equality, like, not like, etc.

Code

function value_form(&$form, &$form_state) {
  // 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';
  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 ($which == 'all' || $which == 'value') {
    $form['value'] = array(
      '#type' => 'textfield',
      '#title' => t('Value'),
      '#size' => 30,
      '#default_value' => $this->value,
    );
    if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
      $form_state['input'][$identifier] = $this->value;
    }

    if ($which == 'all') {
      // Setup #states for all operators with one value.
      foreach ($this->operator_values(1) as $operator) {
        $form['value']['#states']['visible'][] = array(
          $source => array('value' => $operator),
        );
      }
    }
  }

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