current_search.module 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * @file
  4. * Provides an interface for creating blocks containing information about the
  5. * current search.
  6. */
  7. /**
  8. * Display current search block only when keywords are entered.
  9. */
  10. define('CURRENT_SEARCH_DISPLAY_KEYS', 0);
  11. /**
  12. * Display current search block on empty searches where no keywords are entered.
  13. */
  14. define('CURRENT_SEARCH_DISPLAY_ALWAYS', 1);
  15. /**
  16. * Display current search block only when one or more facet items are active.
  17. */
  18. define('CURRENT_SEARCH_DISPLAY_FILTERS', 2);
  19. /**
  20. * Display current search block when either keywords are entered one or more
  21. * facet items are active.
  22. */
  23. define('CURRENT_SEARCH_DISPLAY_KEYS_FILTERS', 3);
  24. // Includes the Block hooks and form alterations.
  25. require_once dirname(__FILE__) . '/current_search.block.inc';
  26. /**
  27. * Implements hook_menu_alter().
  28. */
  29. function current_search_menu() {
  30. $items = array();
  31. $items['admin/config/search/current_search/item/%current_search_item/delete/%'] = array(
  32. 'title' => 'Revert current search block configuration',
  33. 'page callback' => 'drupal_get_form',
  34. 'page arguments' => array('current_search_delete_item_form', 5, 7),
  35. 'access arguments' => array('administer search'),
  36. 'type' => MENU_NORMAL_ITEM,
  37. 'file' => 'plugins/export_ui/current_search_export_ui.class.php',
  38. );
  39. return $items;
  40. }
  41. /**
  42. * Implements hook_menu_alter().
  43. */
  44. function current_search_menu_alter(&$items) {
  45. // Use same access callback as Facet API. We can't define access callbacks in
  46. // CTools plugins, so we have to alter the menu and define them here.
  47. $base_path = 'admin/config/search/current_search';
  48. foreach ($items as $path => $item) {
  49. if ($base_path == $path || 0 === strpos($path, "$base_path/")) {
  50. $items[$path]['access callback'] = 'facetapi_access_callback';
  51. $items[$path]['access arguments'] = array();
  52. }
  53. }
  54. // Ensures that the edit link shows up in contextual links.
  55. $item = &$items['admin/config/search/current_search/list/%ctools_export_ui/edit'];
  56. $item['title'] = 'Configure current search items';
  57. $item['type'] = MENU_LOCAL_ACTION;
  58. $item['context'] = MENU_CONTEXT_INLINE;
  59. }
  60. /**
  61. * Implements hook_theme().
  62. */
  63. function current_search_theme() {
  64. return array(
  65. 'current_search_group_title' => array(
  66. 'arguments' => array('title' => NULL),
  67. 'file' => 'current_search.theme.inc',
  68. ),
  69. 'current_search_text' => array(
  70. 'arguments' => array('text' => NULL, 'wrapper' => NULL, 'element' => NULL, 'css' => NULL, 'class' => array()),
  71. 'file' => 'current_search.theme.inc',
  72. ),
  73. 'current_search_link_active' => array(
  74. 'arguments' => array('text' => NULL, 'path' => NULL, 'options' => array()),
  75. 'file' => 'current_search.theme.inc',
  76. ),
  77. 'current_search_keys' => array(
  78. 'arguments' => array('keys' => NULL, 'adapter' => NULL),
  79. 'file' => 'current_search.theme.inc',
  80. ),
  81. 'current_search_deactivate_widget' => array(
  82. 'file' => 'current_search.theme.inc',
  83. ),
  84. 'current_search_item_wrapper' => array(
  85. 'render element' => 'element',
  86. 'file' => 'current_search.theme.inc',
  87. ),
  88. 'current_search_group_wrapper' => array(
  89. 'render element' => 'element',
  90. 'file' => 'current_search.theme.inc',
  91. ),
  92. 'current_search_sort_settings_table' => array(
  93. 'render element' => 'element',
  94. 'file' => 'current_search.theme.inc',
  95. ),
  96. );
  97. }
  98. /**
  99. * Implements hook_ctools_plugin_api().
  100. */
  101. function current_search_ctools_plugin_api($owner, $api) {
  102. if ('current_search' == $owner && 'current_search' == $api) {
  103. return array('version' => 1);
  104. }
  105. }
  106. /**
  107. * Implements hook_ctools_plugin_directory().
  108. */
  109. function current_search_ctools_plugin_directory($module, $type) {
  110. if ('export_ui' == $type) {
  111. return 'plugins/export_ui';
  112. }
  113. }
  114. /**
  115. * Implements hook_ctools_plugin_type().
  116. */
  117. function current_search_ctools_plugin_type() {
  118. return array(
  119. 'items' => array(
  120. 'use hooks' => TRUE,
  121. ),
  122. );
  123. }
  124. /**
  125. * Returns an array of available current search plugins.
  126. *
  127. * @return array
  128. * An associative array keyed by plugin ID to human readable label.
  129. */
  130. function current_search_get_plugins() {
  131. $plugins = &drupal_static(__FUNCTION__, array());
  132. if (!$plugins) {
  133. foreach (ctools_get_plugins('current_search', 'items') as $id => $plugin) {
  134. $plugins[$id] = $plugin['handler']['label'];
  135. }
  136. }
  137. return $plugins;
  138. }
  139. /**
  140. * Returns an array of searcher options.
  141. *
  142. * @return
  143. * An array of options.
  144. */
  145. function current_search_get_searcher_options() {
  146. $options = array();
  147. foreach (facetapi_get_searcher_info() as $name => $info) {
  148. $options[$name] = $info['label'];
  149. }
  150. return $options;
  151. }
  152. /**
  153. * Returns the settings for a current search block configuration.
  154. *
  155. * @param $name
  156. * The machine readable name of the configuration.
  157. *
  158. * @return stdClass
  159. * An object containing the configuration, FALSE if not defined.
  160. */
  161. function current_search_item_load($name) {
  162. ctools_include('export');
  163. $result = ctools_export_crud_load('current_search', $name);
  164. return $result ? $result : FALSE;
  165. }
  166. /**
  167. * Implements hook_current_search_items().
  168. */
  169. function current_search_current_search_items() {
  170. return array(
  171. 'text' => array(
  172. 'handler' => array(
  173. 'label' => t('Custom text'),
  174. 'class' => 'CurrentSearchItemText',
  175. ),
  176. ),
  177. 'active' => array(
  178. 'handler' => array(
  179. 'label' => t('Active items'),
  180. 'class' => 'CurrentSearchItemActive',
  181. ),
  182. ),
  183. 'group' => array(
  184. 'handler' => array(
  185. 'label' => t('Field group'),
  186. 'class' => 'CurrentSearchGroup',
  187. ),
  188. ),
  189. );
  190. }