function views_handler_filter_string::value_form

3.x views_handler_filter_string.inc views_handler_filter_string::value_form(&$form, &$form_state)
2.x 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

handlers/views_handler_filter_string.inc, line 183
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 = ($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 ($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') {
      $form['value'] += array(
        '#dependency' => array($source => $this->operator_values(1)),
      );
    }
  }

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