function views_handler_filter_in_operator::value_form

Same name in other branches
  1. 7.x-3.x handlers/views_handler_filter_in_operator.inc \views_handler_filter_in_operator::value_form()

Overrides views_handler_filter::value_form

1 call to views_handler_filter_in_operator::value_form()
views_handler_filter_many_to_one::value_form in handlers/views_handler_filter_many_to_one.inc
Provide a form for setting options.
2 methods override views_handler_filter_in_operator::value_form()
views_handler_filter_many_to_one::value_form in handlers/views_handler_filter_many_to_one.inc
Provide a form for setting options.
views_handler_filter_user_name::value_form in modules/user/views_handler_filter_user_name.inc
Provide a form for setting options.

File

handlers/views_handler_filter_in_operator.inc, line 149

Class

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

Code

function value_form(&$form, &$form_state) {
    $form['value'] = array();
    $this->get_value_options();
    $options = $this->value_options;
    $default_value = (array) $this->value;
    $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'])) {
            // exposed and locked.
            $which = in_array($this->operator, $this->operator_values(1)) ? 'value' : 'none';
        }
        else {
            $source = 'edit-' . form_clean_id($this->options['expose']['operator']);
        }
        if (!empty($this->options['expose']['reduce'])) {
            $options = $this->reduce_value_options();
            if (empty($this->options['expose']['single']) && !empty($this->options['expose']['optional'])) {
                $default_value = array();
            }
        }
        if (!empty($this->options['expose']['single'])) {
            if (!empty($this->options['expose']['optional']) && (empty($default_value) || !empty($this->options['expose']['reduce']))) {
                $default_value = 'All';
            }
            else {
                if (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;
        }
        $process = array();
        if ($this->value_form_type == 'checkboxes') {
            // If this form element will use checkboxes in the UI, we need to
            // check_plain() all the options ourselves since FAPI is inconsistent
            // about this. However, instead of directly doing that to the #options
            // right now, we define a #process callback since we might change our
            // mind later and convert this into a 'select' form element, which
            // would lead to double-escaping the options.
            $process[] = 'views_process_check_options';
        }
        if ($which == 'all') {
            if (empty($form_state['exposed']) && ($this->value_form_type == 'checkboxes' || $this->value_form_type == 'radios')) {
                $process[] = "expand_{$this->value_form_type}";
                $form['value']['#prefix'] = '<div id="edit-options-value-wrapper">';
                $form['value']['#suffix'] = '</div>';
            }
            $process[] = 'views_process_dependency';
            $form['value']['#dependency'] = array(
                $source => $this->operator_values(1),
            );
        }
        if (!empty($process)) {
            $form['value']['#process'] = $process;
        }
    }
}