You are here

public function views_handler_filter_selective::options_form in Views Selective Filters 7

Provide the basic form which calls through to subforms.

If overridden, it is best to call through to the parent, or to at least make sure all of the functions in this form are called.

Overrides views_handler_filter::options_form

File

./views_handler_filter_selective.inc, line 102
Views Filter Selective Handler Overrides.

Class

views_handler_filter_selective
Views filter handler for selective values.

Code

public function options_form(&$form, &$form_state) {
  $base_field = $this->definition['field_base'];
  parent::options_form($form, $form_state);

  // Filter should always be exposed, show warning.
  array_unshift($form['expose_button'], array(
    'warning' => array(
      '#type' => 'markup',
      '#markup' => '<div class="messages warning">' . t('This filter is always exposed to users.') . '</div>',
    ),
  ));

  // Remove option to unexpose filter. Tried to disable, but did not work.
  $form['expose_button']['checkbox']['checkbox']['#type'] = 'hidden';
  unset($form['expose_button']['button']);
  unset($form['expose_button']['markup']);

  // Do not allow to check "all values".
  $form['value']['#attributes']['disabled'] = 'disabled';

  // Cannot group without values.
  unset($form['group_button']);

  // Preload handlers, sorts and filters.
  // This gest cached all along.
  $this->view->display_handler
    ->get_handlers('field');
  $this->view->display_handler
    ->get_handlers('sort');
  $this->view->display_handler
    ->get_handlers('filter');

  // Add combo to pick display field for filter.
  $options = array();
  foreach ($this->view->display_handler->handlers['field'] as $key => $handler) {
    if ($this
      ->baseFieldCompatible($base_field, $handler->field)) {
      $options[$handler->options['id']] = $handler->definition['group'] . ': ' . $handler->definition['title'] . '(' . $handler
        ->label() . ')';
    }
  }
  $form['selective_display_field'] = array(
    '#title' => t('Display field'),
    '#type' => 'select',
    '#description' => t('Field to be used for the selective options.'),
    '#options' => $options,
    '#default_value' => $this->options['selective_display_field'],
  );

  // Add combo to pick sort for display.
  $options = array();
  $options['NONE'] = t('No sorting');

  // Add option for custom sortings.
  if ($this
    ->getOriginalOptions()) {
    $options['ORIG'] = t('As the original filter');
  }
  $options['KASC'] = t('Custom key ascending (ksort)');
  $options['KDESC'] = t('Custom key descending (ksort reverse)');
  $options['ASC'] = t('Custom ascending (asort)');
  $options['DESC'] = t('Custom descending (asort reverse)');

  // TODO: Allow the use of view's sorts!

  //foreach ($this->view->display_handler->handlers['sort'] as $key => $handler) {

  //  $options[$handler->options['id']] = $handler->definition['group'] . ': ' . $handler->definition['title'];

  //}
  $form['selective_display_sort'] = array(
    '#title' => t('Sort field'),
    '#type' => 'select',
    '#description' => t('Choose wich field to use for display'),
    '#options' => $options,
    '#default_value' => $this->options['selective_display_sort'],
  );
  $form['selective_items_limit'] = array(
    '#title' => t('Limit number of select items'),
    '#type' => 'textfield',
    '#description' => t("Don't allow a badly configured selective filter to return thousands of possible values. Enter a limit or remove any value for no limit. We recommend to set a limit no higher than 100."),
    '#default_value' => $this->options['selective_items_limit'],
    '#size' => 10,
    '#element_validate' => array(
      'element_validate_integer_positive',
    ),
  );
  $form['selective_options_ignore_exposed_data'] = array(
    '#title' => t('Always show default set of options, even after exposed filters have been applied'),
    '#type' => 'checkbox',
    '#description' => t("If you don't want the filter options to continue to be filtered as additional exposed filters are applied, check this box"),
    '#default_value' => $this->options['selective_options_ignore_exposed_data'],
  );
}