You are here

function better_exposed_filters_exposed_form_plugin::options_form in Better Exposed Filters 6.3

Same name and namespace in other branches
  1. 6 better_exposed_filters_exposed_form_plugin.inc \better_exposed_filters_exposed_form_plugin::options_form()
  2. 7.3 better_exposed_filters_exposed_form_plugin.inc \better_exposed_filters_exposed_form_plugin::options_form()
  3. 7 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 22
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 the same options we used to add in hook_form_alter()
  foreach ($this->display->handler
    ->get_handlers('filter') as $label => $filter) {
    if (!$filter->options['exposed']) {
      continue;
    }

    // Set to TRUE if this is a BEF-specific filter, namely one that we can
    // rewrite in the theme layer. We still offer some additional options for
    // all filters such as adding a description field.
    $is_bef_filter = FALSE;

    // We can tweak with these types of filter handlers (and their children)
    $valid_classes = array(
      'views_handler_filter_boolean_operator',
      'views_handler_filter_in_operator',
    );
    foreach ($valid_classes as $class) {
      if ($filter instanceof $class) {
        $is_bef_filter = TRUE;
        break;
      }
    }
    if ($is_bef_filter) {

      // 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(
          '#value' => '<div class="form-item"><h3>' . t('Exposed Filter Settings') . '</h3><p>' . t('Select a format and additional options for each exposed filter.') . '</p><p>' . t('If <em>Force single</em> option is checked in the <em>Configure
                  filter</em> form then radio buttons will be used, otherwise
                  checkboxes. The "Nested" option allows hierarchical taxonomy
                  filters will be rendered as nested, unordered lists. The "Hidden"
                  option is generally used for multi-step filters.') . '</p><p>' . t('Additional options are available for each filter by clicking the
                  <em>More options</em> link.') . '</p></div>',
        );
        $bef_filter_intro = TRUE;
      }

      // Main BEF option: default or radios/checkboxes
      $display_options = array(
        'default' => t('Default select list'),
        'bef' => t('Checkboxes/Radio Buttons'),
      );

      // Taxonomy filters get the "nested" option
      if ($filter instanceof views_handler_filter_term_node_tid) {
        $display_options['bef_ul'] = t('Nested Checkboxes/Radio Buttons');
      }

      // Check for other display options based on the filter
      if ($filter instanceof views_handler_filter_boolean_operator && $filter->options['expose']['single']) {
        $display_options['bef_single'] = t('Single on/off checkbox');
      }

      // Hidden option is least used, so put it last
      $display_options['bef_hidden'] = t('Hidden');
      $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' => $display_options,
      );
    }

    // 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 ($is_bef_filter) {
      $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']['single'],
        '#description' => t('Add a "Select All/None" link when rendering the exposed filter using
              checkboxes. If this option is disabled, edit the filter and uncheck
              "Force single". NOTE: The link is built at page load, so it will not appear
              in the "Live Preview" which is loaded dynamically.'),
      );

      // Put filter in collapsible fieldset option
      $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'),
      );
    }

    // Add node count for Taxonomy-based filters
    if (t('Taxonomy') == $filter->definition['group']) {
      $bef_options[$label]['more_options']['bef_show_term_count'] = array(
        '#type' => 'checkbox',
        '#title' => t('Show term node count'),
        '#default_value' => $this->options['bef'][$label]['more_options']['bef_show_term_count'],
        '#description' => t('Show number of nodes after each term, in paranthesis, like this:
            "Term A (4), Term B (10)", etc.'),
      );
    }

    // Build a description option form element
    $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;
}