search_extra_type.module

Dummy module implementing a search type for search module testing.

File

drupal-7.x/modules/search/tests/search_extra_type.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Dummy module implementing a search type for search module testing.
  5. */
  6. /**
  7. * Implements hook_search_info().
  8. */
  9. function search_extra_type_search_info() {
  10. return array(
  11. 'title' => 'Dummy search type',
  12. 'path' => 'dummy_path',
  13. 'conditions_callback' => 'search_extra_type_conditions',
  14. );
  15. }
  16. /**
  17. * Test conditions callback for hook_search_info().
  18. */
  19. function search_extra_type_conditions() {
  20. $conditions = array();
  21. if (!empty($_REQUEST['search_conditions'])) {
  22. $conditions['search_conditions'] = $_REQUEST['search_conditions'];
  23. }
  24. return $conditions;
  25. }
  26. /**
  27. * Implements hook_search_execute().
  28. *
  29. * This is a dummy search, so when search "executes", we just return a dummy
  30. * result containing the keywords and a list of conditions.
  31. */
  32. function search_extra_type_search_execute($keys = NULL, $conditions = NULL) {
  33. if (!$keys) {
  34. $keys = '';
  35. }
  36. return array(
  37. array(
  38. 'link' => url('node'),
  39. 'type' => 'Dummy result type',
  40. 'title' => 'Dummy title',
  41. 'snippet' => "Dummy search snippet to display. Keywords: {$keys}\n\nConditions: " . print_r($conditions, TRUE),
  42. ),
  43. );
  44. }
  45. /**
  46. * Implements hook_search_page().
  47. *
  48. * Adds some text to the search page so we can verify that it runs.
  49. */
  50. function search_extra_type_search_page($results) {
  51. $output['prefix']['#markup'] = '<h2>Test page text is here</h2> <ol class="search-results">';
  52. foreach ($results as $entry) {
  53. $output[] = array(
  54. '#theme' => 'search_result',
  55. '#result' => $entry,
  56. '#module' => 'search_extra_type',
  57. );
  58. }
  59. $output['suffix']['#markup'] = '</ol>' . theme('pager');
  60. return $output;
  61. }