function InOperator::value_form

Options form subform for setting options.

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

Overrides FilterPluginBase::value_form

See also

buildOptionsForm()

1 call to InOperator::value_form()
ManyToOne::value_form in drupal/core/modules/views/lib/Drupal/views/Plugin/views/filter/ManyToOne.php
Options form subform for setting options.
2 methods override InOperator::value_form()
ManyToOne::value_form in drupal/core/modules/views/lib/Drupal/views/Plugin/views/filter/ManyToOne.php
Options form subform for setting options.
Name::value_form in drupal/core/modules/user/lib/Drupal/user/Plugin/views/filter/Name.php
Options form subform for setting options.

File

drupal/core/modules/views/lib/Drupal/views/Plugin/views/filter/InOperator.php, line 168
Definition of Drupal\views\Plugin\views\filter\InOperator.

Class

InOperator
Simple filter to handle matching of multiple options selectable via checkboxes

Namespace

Drupal\views\Plugin\views\filter

Code

function value_form(&$form, &$form_state) {
  $form['value'] = array();
  $options = array();
  if (empty($form_state['exposed'])) {

    // Add a select all option to the value form.
    $options = array(
      'all' => t('Select all'),
    );
  }
  $this
    ->get_value_options();
  $options += $this->value_options;
  $default_value = (array) $this->value;
  $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 (!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') {
    $form['value'] = array(
      '#type' => $this->value_form_type,
      '#title' => $this->value_title,
      '#options' => $options,
      '#default_value' => $default_value,
      // These are only valid for 'select' type, but do no harm to checkboxes.
      '#multiple' => TRUE,
      '#size' => count($options) > 8 ? 8 : count($options),
    );
    if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
      $form_state['input'][$identifier] = $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>';
      }

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