You are here

function better_exposed_filters_exposed_form_plugin::options_form in Better Exposed Filters 7

Same name and namespace in other branches
  1. 6.3 better_exposed_filters_exposed_form_plugin.inc \better_exposed_filters_exposed_form_plugin::options_form()
  2. 6 better_exposed_filters_exposed_form_plugin.inc \better_exposed_filters_exposed_form_plugin::options_form()
  3. 7.3 better_exposed_filters_exposed_form_plugin.inc \better_exposed_filters_exposed_form_plugin::options_form()

Provide a form to edit options for this plugin.

Overrides views_plugin_exposed_form::options_form

File

./better_exposed_filters_exposed_form_plugin.inc, line 21
Provides an Better Exposed Filters exposed form plugin for View 3.x.

Class

better_exposed_filters_exposed_form_plugin
@file Provides an Better Exposed Filters exposed form plugin for View 3.x.

Code

function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);
  $bef_options = array();

  /*
   * Add options for exposed sorts
   */
  $exposed = FALSE;
  foreach ($this->display->handler
    ->get_handlers('sort') as $label => $sort) {
    if ($sort->options['exposed']) {
      $exposed = TRUE;
      break;
    }
  }
  if ($exposed) {
    $bef_options['sort']['bef_format'] = array(
      '#type' => 'select',
      '#title' => t('Display exposed sort options as'),
      '#default_value' => $this->options['bef']['sort']['bef_format'],
      '#options' => array(
        'default' => t('Default select list'),
        'bef' => t('Radio Buttons'),
        'bef_links' => t('Links'),
      ),
      '#description' => t('Select a format for the exposed sort options.'),
    );
    $bef_options['sort']['combine'] = array(
      '#type' => 'checkbox',
      '#title' => t('Combine sort order with sort by'),
      '#default_value' => $this->options['bef']['sort']['combine'],
      '#description' => t('Combines the sort by options and order (ascending or decending) into a single list.  Use this to
          display "Option1 (ascending)", "Option1 (descending)", "Option2 (ascending)", "Option2 (descending)"
          in a single form element.'),
    );
    $bef_options['sort']['reset'] = array(
      '#type' => 'checkbox',
      '#title' => t('Include a "Reset sort" option'),
      '#default_value' => $this->options['bef']['sort']['reset'],
      '#description' => t('Adds a "Reset sort" link; Views will use the default sort order.'),
    );
    $bef_options['sort']['reset_label'] = array(
      '#type' => 'textfield',
      '#title' => t('"Reset sort" label'),
      '#default_value' => $this->options['bef']['sort']['reset_label'],
      '#description' => t('Text to use if the above option is checked'),
    );
  }

  /*
   * Add options for exposed pager
   */
  if ($this->display->display_options['pager'] && $this->display->display_options['pager']['options']['expose']['items_per_page']) {
    $bef_options['pager']['bef_format'] = array(
      '#type' => 'select',
      '#title' => t('Display exposed pager options as'),
      '#default_value' => $this->options['bef']['pager']['bef_format'],
      '#options' => array(
        'default' => t('Default select list'),
        'bef' => t('Radio Buttons'),
        'bef_links' => t('Links'),
      ),
      '#description' => t('Select a format for the exposed pager options.'),
    );
  }

  // Only add the description text once -- it was getting a little long to be added to
  // each filter
  $bef_filter_intro = FALSE;

  // Go through each filter and add BEF options
  foreach ($this->display->handler
    ->get_handlers('filter') as $label => $filter) {
    if (!$filter->options['exposed']) {
      continue;
    }

    // If we're adding BEF filter options, add an intro to explain what's going on
    if (!$bef_filter_intro) {
      $bef_options['bef_intro'] = array(
        '#markup' => '<h3>' . t('Exposed Filter Settings') . '</h3><p>' . t('Select a format and additional options for each exposed filter.') . '</p><p>' . t('The "Nested" option places filter options is an unordered list.
                Hierarchical taxonomy filters will be rendered as nested,
                unordered lists. "Links" will render filter options as links,
                but is only available if "Allow multiple selections"
                is NOT checked in the "Configure filter criterion" form. The "Hidden"
                option is generally used for multi-step filters.  Note: if "Allow multiple
                selections" is checked in the "Configure filter criterion" form,
                checkboxes will be used, otherwise radio buttons.') . '</p><p>' . t('You may also add an optional description for any exposed filter
                in the "More options" section.') . '</p>',
      );
      $bef_filter_intro = TRUE;
    }

    // Is this a type of field we can tweak? If so, we'll display additional options.
    $valid = array(
      'in',
      'or',
    );
    $bef_specific = FALSE;

    // We can work with any of these operators
    if (in_array($filter->operator, $valid)) {
      $bef_specific = TRUE;
    }
    else {
      if ('yes-no' == $filter->definition['type']) {

        // others?
        $bef_specific = TRUE;
      }
      else {

        // dsm($filter->definition['type']);
      }
    }

    // Main BEF option: default/checkboxes/hidden/etc.
    if ($bef_specific) {
      $bef_options[$label]['bef_format'] = array(
        '#type' => 'select',
        '#title' => t('Display "@label" exposed filter as', array(
          '@label' => $filter->options['expose']['label'],
        )),
        '#default_value' => $this->options['bef'][$label]['bef_format'],
        '#options' => array(
          'default' => t('Default select list'),
          'bef' => t('Checkboxes/Radio Buttons'),
          'bef_ul' => t('Nested Checkboxes/Radio Buttons'),
          'bef_links' => t('Links'),
          'bef_hidden' => t('Hidden'),
        ),
      );
    }

    // Fieldset to keep the UI from getting out of hand
    $bef_options[$label]['more_options'] = array(
      '#type' => 'fieldset',
      '#title' => t('More options for "@label"', array(
        '@label' => $filter->options['expose']['label'],
      )),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );

    // Select all checkbox
    if ($bef_specific) {
      $bef_options[$label]['more_options']['bef_select_all_none'] = array(
        '#type' => 'checkbox',
        '#title' => t('Add select all/none links'),
        '#default_value' => $this->options['bef'][$label]['more_options']['bef_select_all_none'],
        '#disabled' => !$filter->options['expose']['multiple'],
        '#description' => t('Add a "Select All/None" link when rendering the exposed filter using
              checkboxes. If this option is disabled, edit the filter and check the
              "Allow multiple selections".'),
      );

      // Put filter in collapsible fieldset option
      // TODO: expand to all exposed filters
      $bef_options[$label]['more_options']['bef_collapsible'] = array(
        '#type' => 'checkbox',
        '#title' => t('Make this filter collapsible'),
        '#default_value' => $this->options['bef'][$label]['more_options']['bef_collapsible'],
        '#description' => t('Puts this filter in a collapsible fieldset'),
      );
    }

    // Build a description option form element -- available to all exposed filters
    $bef_options[$label]['more_options']['bef_filter_description'] = array(
      '#type' => 'textarea',
      '#title' => t('Description'),
      '#default_value' => $this->options['bef'][$label]['more_options']['bef_filter_description'],
      '#description' => t('Adds descriptive text to the exposed filter.  This is usually
                              rendered in smaller print under the label or the options.'),
    );
  }

  // foreach ($filters as $filter) {
  // Add BEF form elements to the exposed form options form
  $form['bef'] = $bef_options;
}