You are here

current_search.module in Facet API 6.3

Provides an interface for creating blocks containing information about the current search.

File

contrib/current_search/current_search.module
View source
<?php

/**
 * @file
 * Provides an interface for creating blocks containing information about the
 * current search.
 */

/**
 * Display current search block only when keywords are entered.
 */
define('CURRENT_SEARCH_DISPLAY_KEYS', 0);

/**
 * Display current search block on empty searches where no keywords are entered.
 */
define('CURRENT_SEARCH_DISPLAY_ALWAYS', 1);

/**
 * Display current search block only when one or more facet items are active.
 */
define('CURRENT_SEARCH_DISPLAY_FILTERS', 2);

/**
 * Display current search block when either keywords are entered one or more
 * facet items are active.
 */
define('CURRENT_SEARCH_DISPLAY_KEYS_FILTERS', 3);

// Includes the Block hooks and form alterations.
require_once dirname(__FILE__) . '/current_search.block.inc';

/**
 * Implements hook_menu_alter().
 */
function current_search_menu() {
  $items = array();
  $items['admin/settings/current_search/item/%current_search_item/delete/%'] = array(
    'title' => 'Revert current search block configuration',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'current_search_delete_item_form',
      5,
      7,
    ),
    'access arguments' => array(
      'administer search',
    ),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'plugins/export_ui/current_search_export_ui.class.php',
  );
  return $items;
}

/**
 * Implements hook_menu_alter().
 */
function current_search_menu_alter(&$items) {

  // Use same access callback as Facet API. We can't define access callbacks in
  // CTools plugins, so we have to alter the menu and define them here.
  $base_path = 'admin/settings/current_search';
  foreach ($items as $path => $item) {
    if ($base_path == $path || 0 === strpos($path, "{$base_path}/")) {
      $items[$path]['access callback'] = 'facetapi_access_callback';
      $items[$path]['access arguments'] = array();
    }
  }

  // Ensures that the edit link shows up in contextual links.
  $item =& $items['admin/settings/current_search/list/%ctools_export_ui/edit'];
  $item['title'] = 'Configure current search items';
  $item['type'] = MENU_CALLBACK;

  //$item['context'] = MENU_CONTEXT_INLINE;
}

/**
 * Implements hook_theme().
 */
function current_search_theme() {
  module_load_include('php', 'ctools', 'plugins/export_ui/ctools_export_ui.class');
  return array(
    'current_search_group_title' => array(
      'arguments' => array(
        'title' => NULL,
      ),
      'file' => 'current_search.theme.inc',
    ),
    'current_search_text' => array(
      'arguments' => array(
        'text' => NULL,
        'wrapper' => NULL,
        'element' => NULL,
        'css' => NULL,
        'class' => NULL,
      ),
      'file' => 'current_search.theme.inc',
    ),
    'current_search_link_active' => array(
      'arguments' => array(
        'text' => NULL,
        'path' => NULL,
        'options' => array(),
      ),
      'file' => 'current_search.theme.inc',
    ),
    'current_search_keys' => array(
      'arguments' => array(
        'keys' => NULL,
        'adapter' => NULL,
      ),
      'file' => 'current_search.theme.inc',
    ),
    'current_search_deactivate_widget' => array(
      'file' => 'current_search.theme.inc',
    ),
    'current_search_item_wrapper' => array(
      'render element' => 'element',
      'file' => 'current_search.theme.inc',
    ),
    'current_search_group_wrapper' => array(
      'render element' => 'element',
      'file' => 'current_search.theme.inc',
    ),
    'current_search_sort_settings_table' => array(
      'render element' => 'element',
      'file' => 'plugins/export_ui/current_search_export_ui.class.php',
    ),
  );
}

/**
 * Implements hook_ctools_plugin_api().
 */
function current_search_ctools_plugin_api($owner, $api) {
  if ('current_search' == $owner && 'current_search' == $api) {
    return array(
      'version' => 1,
    );
  }
}

/**
 * Implements hook_ctools_plugin_directory().
 */
function current_search_ctools_plugin_directory($module, $type) {
  if ('ctools' == $module && 'export_ui' == $type) {
    return 'plugins/export_ui';
  }
  if ('current_search' == $module) {
    return 'plugins/current_search';
  }
}

/**
 * Implements hook_ctools_plugin_type().
 */
function current_search_ctools_plugin_items() {
  return array(
    'use hooks' => TRUE,
  );
}

/**
 * Returns an array of available current search plugins.
 *
 * @return array
 *   An associative array keyed by plugin ID to human readable label.
 */
function current_search_get_plugins() {
  $plugins =& ctools_static(__FUNCTION__, array());
  if (!$plugins) {
    foreach (ctools_get_plugins('current_search', 'items') as $id => $plugin) {
      $plugins[$id] = $plugin['handler']['label'];
    }
  }
  return $plugins;
}

/**
 * Returns an array of searcher options.
 *
 * @return
 *   An array of options.
 */
function current_search_get_searcher_options() {
  $options = array();
  foreach (facetapi_get_searcher_info() as $name => $info) {
    $options[$name] = $info['label'];
  }
  return $options;
}

/**
 * Returns the settings for a current search block configuration.
 *
 * @param $name
 *   The machine readable name of the configuration.
 *
 * @return stdClass
 *   An object containing the configuration, FALSE if not defined.
 */
function current_search_item_load($name) {
  ctools_include('export');
  $result = ctools_export_crud_load('current_search', $name);
  return $result ? $result : FALSE;
}

/**
 * Implements hook_current_search_items().
 */
function current_search_current_search_items() {
  $path = drupal_get_path('module', 'current_search') . '/plugins/current_search';
  return array(
    'current_search_item' => array(
      'handler' => array(
        'label' => t('Abstract class for Current Search items'),
        'class' => 'CurrentSearchItem',
        'abstract' => TRUE,
        'path' => $path,
        'file' => 'item.inc',
      ),
    ),
    'text' => array(
      'handler' => array(
        'label' => t('Custom text'),
        'class' => 'CurrentSearchItemText',
        'parent' => 'current_search_item',
        'path' => $path,
        'file' => 'item_text.inc',
      ),
    ),
    'active' => array(
      'handler' => array(
        'label' => t('Active items'),
        'class' => 'CurrentSearchItemActive',
        'parent' => 'current_search_item',
        'path' => $path,
        'file' => 'item_active.inc',
      ),
    ),
    'group' => array(
      'handler' => array(
        'label' => t('Field group'),
        'class' => 'CurrentSearchGroup',
        'parent' => 'current_search_item',
        'path' => $path,
        'file' => 'item_group.inc',
      ),
    ),
  );
}

Functions

Namesort descending Description
current_search_ctools_plugin_api Implements hook_ctools_plugin_api().
current_search_ctools_plugin_directory Implements hook_ctools_plugin_directory().
current_search_ctools_plugin_items Implements hook_ctools_plugin_type().
current_search_current_search_items Implements hook_current_search_items().
current_search_get_plugins Returns an array of available current search plugins.
current_search_get_searcher_options Returns an array of searcher options.
current_search_item_load Returns the settings for a current search block configuration.
current_search_menu Implements hook_menu_alter().
current_search_menu_alter Implements hook_menu_alter().
current_search_theme Implements hook_theme().

Constants

Namesort descending Description
CURRENT_SEARCH_DISPLAY_ALWAYS Display current search block on empty searches where no keywords are entered.
CURRENT_SEARCH_DISPLAY_FILTERS Display current search block only when one or more facet items are active.
CURRENT_SEARCH_DISPLAY_KEYS Display current search block only when keywords are entered.
CURRENT_SEARCH_DISPLAY_KEYS_FILTERS Display current search block when either keywords are entered one or more facet items are active.