diff --git a/search-api-page-result.tpl.php b/search-api-page-result.tpl.php new file mode 100644 index 0000000..bf56e48 --- /dev/null +++ b/search-api-page-result.tpl.php @@ -0,0 +1,56 @@ +'. check_plain(print_r($info_split, 1)) .''; ?> + * @endcode + * + * @see template_preprocess() + * @see template_preprocess_search_result() + * @see template_process() + */ +?> +
', + '#suffix' => '
', ); } @@ -49,11 +53,12 @@ function search_api_page_view($id, $keys = NULL) { $ret['results']['#results'] = $results; $ret['results']['#view_mode'] = isset($page->options['view_mode']) ? $page->options['view_mode'] : 'search_api_page_result'; $ret['results']['#keys'] = $keys; + $ret['results']['#page_machine_name'] = $page->machine_name; + // Load pager. if ($results['result count'] > $page->options['per_page']) { pager_default_initialize($results['result count'], $page->options['per_page']); - $ret['pager']['#theme'] = 'pager'; - $ret['pager']['#quantity'] = 9; + $ret['results']['#pager'] = theme('pager'); } if (!empty($results['ignored'])) { @@ -108,96 +113,66 @@ function search_api_page_search_execute(Entity $page, $keys) { /** * Function for preprocessing the variables for the search_api_page_results - * theme. + * template. * * @param array $variables * An associative array containing: - * - index: The index this search was executed on. - * - results: An array of search results, as returned by + * - $index: The index this search was executed on. + * - $results: An array of search results, as returned by * SearchApiQueryInterface::execute(). - * - keys: The keywords of the executed search. - */ -function template_preprocess_search_api_page_results(array &$variables) { - if (!empty($variables['results']['results'])) { - $variables['items'] = $variables['index']->loadItems(array_keys($variables['results']['results'])); - } -} - -/** - * Theme function for displaying search results. + * - $keys: The keywords of the executed search. * - * @param array $variables - * An associative array containing: - * - index: The index this search was executed on. - * - results: An array of search results, as returned by - * SearchApiQueryInterface::execute(). - * - items: The loaded items for all results, in an array keyed by ID. - * - view_mode: The view mode to use for displaying the individual results, - * or the special mode "search_api_page_result" to use the theme function - * of the same name. - * - keys: The keywords of the executed search. + * @see search_api_page-results.tpl.php */ -function theme_search_api_page_results(array $variables) { - drupal_add_css(drupal_get_path('module', 'search_api_page') . '/search_api_page.css'); - - $index = $variables['index']; +function template_preprocess_search_api_page_results(array &$variables) { $results = $variables['results']; - $items = $variables['items']; $keys = $variables['keys']; - $output = '' . format_plural($results['result count'], - 'The search found 1 result in @sec seconds.', - 'The search found @count results in @sec seconds.', - array('@sec' => round($results['performance']['complete'], 3))) . '
'; - - if (!$results['result count']) { - $output .= "\n', + '#suffix' => '
', + ); - return $output; + $variables['search_results'] = array( + '#theme' => 'search_results_list', + 'results' => $variables['results']['results'], + 'items' => $variables['items'], + 'index' => $variables['index'], + 'type' => 'ul', + ); } /** - * Theme function for displaying search results. + * Process variables for search-result.tpl.php. * - * @param array $variables - * An associative array containing: - * - index: The index this search was executed on. - * - result: One item of the search results, an array containing the keys - * 'id' and 'score'. - * - item: The loaded item corresponding to the result. - * - keys: The keywords of the executed search. + * The $variables array contains the following arguments: + * - $result + * + * @see search_api_page-result.tpl.php */ -function theme_search_api_page_result(array $variables) { +function template_preprocess_search_api_page_result(&$variables) { $index = $variables['index']; - $id = $variables['result']['id']; + $variables['id'] = $variables['result']['id']; + $variables['excerpt'] = $variables['result']['excerpt']; $item = $variables['item']; $wrapper = $index->entityWrapper($item, FALSE); - $url = $index->datasource()->getItemUrl($item); - $name = $index->datasource()->getItemLabel($item); + $variables['url'] = $index->datasource()->getItemUrl($item); + $variables['title'] = $index->datasource()->getItemLabel($item); - if (!empty($variables['result']['excerpt'])) { - $text = $variables['result']['excerpt']; + if (!empty($variables['excerpt'])) { + $text = $variables['excerpt']; } else { $fields = $index->options['fields']; @@ -239,10 +214,24 @@ function theme_search_api_page_result(array $variables) { } } - $output = '