You are here

public function SearchApiViewsHandlerFilterOptions::value_form in Search API 7

Provide a form for setting options.

Overrides SearchApiViewsHandlerFilter::value_form

File

contrib/search_api_views/includes/handler_filter_options.inc, line 160
Contains the SearchApiViewsHandlerFilterOptions class.

Class

SearchApiViewsHandlerFilterOptions
Views filter handler for fields with a limited set of possible values.

Code

public function value_form(&$form, &$form_state) {
  $this
    ->get_value_options();
  if (!empty($this->options['expose']['reduce']) && !empty($form_state['exposed'])) {
    $options = $this
      ->reduce_value_options();
  }
  else {
    $options = $this->value_options;
  }
  $form['value'] = array(
    '#type' => $this->value_form_type,
    '#title' => empty($form_state['exposed']) ? t('Value') : '',
    '#options' => $options,
    '#multiple' => TRUE,
    '#size' => min(4, count($options)),
    '#default_value' => is_array($this->value) ? $this->value : array(),
  );

  // Hide the value box if the operator is 'empty' or 'not empty'.
  // Radios share the same selector so we have to add some dummy selector.
  if (empty($form_state['exposed'])) {
    $form['value']['#states']['visible'] = array(
      ':input[name="options[operator]"],dummy-empty' => array(
        '!value' => 'empty',
      ),
      ':input[name="options[operator]"],dummy-not-empty' => array(
        '!value' => 'not empty',
      ),
    );
  }
  elseif (!empty($this->options['expose']['use_operator'])) {
    $name = $this->options['expose']['operator_id'];
    $form['value']['#states']['visible'] = array(
      ':input[name="' . $name . '"],dummy-empty' => array(
        '!value' => 'empty',
      ),
      ':input[name="' . $name . '"],dummy-not-empty' => array(
        '!value' => 'not empty',
      ),
    );
  }
}