You are here

vefl.module in Views exposed form layout 7

Same filename and directory in other branches
  1. 8.3 vefl.module
  2. 8 vefl.module
  3. 8.2 vefl.module

Provides functionality to output Views exposed filters in layout.

File

vefl.module
View source
<?php

/**
 * @file
 * Provides functionality to output Views exposed filters in layout.
 */

/**
 * Include files.
 */
ctools_include('ds', 'vefl');
ctools_include('vefl', 'vefl');
ctools_include('panels', 'vefl');

/**
 * Implements hook_theme().
 */
function vefl_theme() {
  $path = drupal_get_path('module', 'vefl');
  $themes = array();
  $themes['views_exposed_widget'] = array(
    'render element' => 'elements',
    'arguments' => array(
      'widget' => NULL,
    ),
    'template' => 'views-exposed-widget',
    'path' => $path . '/theme',
  );
  if (module_exists('panels')) {
    $themes['vefl_views_exposed_form_panels'] = array(
      'render element' => 'form',
      'theme path' => $path,
      'function' => 'vefl_theme_views_exposed_form_panels',
      'preprocess functions' => array(
        'template_preprocess_views_exposed_form',
        // Use default Views preprocess
        'vefl_views_exposed_form_preprocess',
      ),
    );
  }
  if (module_exists('ds')) {
    $themes['vefl_views_exposed_form_ds'] = array(
      'render element' => 'form',
      'theme path' => $path,
      'function' => 'vefl_theme_views_exposed_form_ds',
      'preprocess functions' => array(
        'template_preprocess_views_exposed_form',
        // Use default Views preprocess
        'vefl_views_exposed_form_preprocess',
      ),
    );
  }
  return $themes;
}

/**
 * Implements hook_theme_registry_alter().
 *
 * Replace default views template for views-exposed-form.tpl.php.
 */
function vefl_theme_registry_alter(&$theme_registry) {
  $module_path = drupal_get_path('module', 'vefl');
  $views_path = drupal_get_path('module', 'views');
  if ($theme_registry['views_exposed_form']['path'] == $views_path . '/theme') {
    $theme_registry['views_exposed_form']['path'] = $module_path . '/theme';
    $theme_registry['views_exposed_form']['theme path'] = $module_path . '/theme';
  }
  $theme_registry['views_exposed_form']['preprocess functions'][] = 'vefl_views_exposed_form_preprocess';

  // Adds additional preprocess function for ds layout.
  if (module_exists('ds')) {
    $module_layouts = ds_get_layout_info();
    foreach ($module_layouts as $id => $layout) {
      if (!empty($layout['module']) && $layout['module'] == 'panels') {
        continue;
      }
      $theme_registry[$id]['preprocess functions'][] = 'vefl_ds_preprocess_layout';
    }
  }
}

/**
 * Returns action fields for views exposed form.
 */
function vefl_form_actions() {
  $actions = array(
    'sort_by' => t('Sort by'),
    'sort_order' => t('Sort order'),
    'items_per_page' => t('Items per page'),
    'offset' => t('Offset'),
    'button' => t('Submit button'),
    'reset_button' => t('Reset button'),
  );
  return $actions;
}

/**
 * Returns array of layouts for exposed form.
 *
 * @param string $layout_id
 *   Will returns info about one layout if layout id passed.
 *
 * @return array
 *   An array contains info about exposed form layouts.
 *
 * @see vefl_vefl_layouts()
 */
function vefl_get_layouts($layout_id = '') {
  $layouts =& drupal_static(__FUNCTION__, array());
  if (empty($layouts)) {
    $layouts = module_invoke_all('vefl_layouts');
  }
  return !empty($layout_id) && !empty($layouts[$layout_id]) ? $layouts[$layout_id] : $layouts;
}

/**
 * Returns name of module which provides layout with given layout_id.
 *
 * @param string $layout_id
 *   Name of layout.
 *
 * @return string
 *   Module name.
 */
function vefl_layout_module($layout_id) {
  $module = 'vefl';
  if (module_exists('panels') && substr($layout_id, 0, 7) == 'panels_') {
    $module = 'panels';
  }
  if (module_exists('ds') && substr($layout_id, 0, 3) == 'ds_') {
    $module = 'ds';
  }
  return $module;
}

/**
 * Generates theme functions by given parameters.
 *
 * @return array
 *   An array of theme function names.
 *
 * @see views_exposed_form()
 */
function _vefl_form_theme_functions($layout_id, $view, $display) {
  $hook = 'views_exposed_form';
  if (vefl_layout_module($layout_id) == 'panels') {
    $hook = 'vefl_views_exposed_form_panels';
  }
  elseif (vefl_layout_module($layout_id) == 'ds') {
    $hook = 'vefl_views_exposed_form_ds';
  }
  return views_theme_functions($hook, $view, $display);
}

/**
 * Helper function to rebuild views exposed form.
 */
function _vefl_change_layout_button($form, &$form_state) {
  $display =& $form_state['view']->display[$form_state['display_id']];
  $display->handler
    ->options_submit($form, $form_state);
  views_ui_cache_set($form_state['view']);
  $form_state['rerender'] = TRUE;
  $form_state['rebuild'] = TRUE;
}

/**
 * Implements hook_views_api().
 */
function vefl_views_api() {
  $path = drupal_get_path('module', 'vefl');
  return array(
    'api' => 3.0,
    'path' => $path . '/views',
  );
}

Functions

Namesort descending Description
vefl_form_actions Returns action fields for views exposed form.
vefl_get_layouts Returns array of layouts for exposed form.
vefl_layout_module Returns name of module which provides layout with given layout_id.
vefl_theme Implements hook_theme().
vefl_theme_registry_alter Implements hook_theme_registry_alter().
vefl_views_api Implements hook_views_api().
_vefl_change_layout_button Helper function to rebuild views exposed form.
_vefl_form_theme_functions Generates theme functions by given parameters.