You are here

mefibs_bef.module in MEFIBS - More exposed forms in blocks 8

Same filename and directory in other branches
  1. 7 modules/mefibs_bef/mefibs_bef.module

Primarily Drupal hooks and global API functions to add support for the Better Exposed Filters module.

File

modules/mefibs_bef/mefibs_bef.module
View source
<?php

/**
 * @file
 * Primarily Drupal hooks and global API functions to add support for the
 * Better Exposed Filters module.
 */

/**
 * Implements hook_init().
 */
function mefibs_bef_init() {

  // Support for better exposed filters.
  if (isset($_REQUEST['mefibs_form']) && $_REQUEST['mefibs_form']) {
    if (isset($_REQUEST[MEFIBS_VIEW_DISPLAY_PREFIX . '-sort_bef_combine'])) {
      $_REQUEST['sort_bef_combine'] = $_REQUEST[MEFIBS_VIEW_DISPLAY_PREFIX . '-sort_bef_combine'];
      list($_REQUEST['sort_by'], $_REQUEST['sort_order']) = explode(' ', $_REQUEST['sort_bef_combine']);
    }
  }
}

/**
 * Implements hook_mefibs_elements_alter().
 */
function mefibs_bef_mefibs_elements_alter(&$elements, $context) {
  $view = $context['view'];
  $display_id = $view->current_display;
  $bef_settings = $view->display[$display_id]->handler
    ->get_option('exposed_form');
  if ($bef_settings['type'] != 'better_exposed_filters') {
    return;
  }
  if (!$bef_settings['options']['bef']['sort']['advanced']['combine']) {
    return;
  }
  if (in_array('sort_by', $elements['sort'])) {
    $elements['sort'][] = 'sort_bef_combine';
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function mefibs_bef_form_views_exposed_form_alter(&$form, $form_state) {
  $view = $form_state['view'];
  $mefibs = $view->display_handler
    ->get_option('mefibs');
  if (!count($mefibs['blocks'])) {
    return;
  }

  // Add javascript needed for ajax form behaviors.
  drupal_add_js(drupal_get_path('module', 'mefibs_bef') . '/mefibs_bef.js');
}