You are here

weight_handler_filter_weight_enabled.inc in Weight 7.2

File

views/weight_handler_filter_weight_enabled.inc
View source
<?php

class weight_handler_filter_weight_enabled extends views_handler_filter {
  function value_form(&$form, &$form_state) {
    if (empty($this->value_options)) {

      // Initialize the array of possible values for this filter.
      $this
        ->get_value_options();
    }
    if (!empty($form_state['exposed'])) {

      // Exposed filter: use a select box to save space.
      $filter_form_type = 'select';
    }
    else {

      // Configuring a filter: use radios for clarity.
      $filter_form_type = 'radios';
    }
    $form['value'] = array(
      '#type' => $filter_form_type,
      '#title' => t('Enabled'),
      '#options' => $this->value_options,
      '#default_value' => $this->value,
    );
    if (!empty($this->options['exposed'])) {
      $identifier = $this->options['expose']['identifier'];
      if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
        $form_state['input'][$identifier] = $this->value;
      }
    }
  }
  function get_value_options() {
    $this->value_options = array(
      1 => t('Yes'),
      0 => t('No'),
    );
  }
  function show_value_form(&$form, &$form_state) {
    $this
      ->value_form($form, $form_state);
  }
  function admin_summary() {
    if (!empty($this->options['exposed'])) {
      return t('exposed');
    }
    if (empty($this->value_options)) {
      $this
        ->get_value_options();
    }

    // Now that we have the valid options for this filter, just return the
    // human-readable label based on the current value.  The value_options
    // array is keyed with either 0 or 1, so if the current value is not
    // empty, use the label for 1, and if it's empty, use the label for 0.
    return $this->value_options[!empty($this->value)];
  }

}