addtemplate patch
http://drupal.org/node/1313676#comment-6169000 Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
+70
-81
@@ -22,7 +22,7 @@ function search_api_page_view($id, $keys = NULL) {
|
||||
$page->options['per_page'] = (int) $_GET['per_page'];
|
||||
}
|
||||
|
||||
if ($page->options['result_page_search_form']) {
|
||||
if (isset($page->options['result_page_search_form']) && $page->options['result_page_search_form']) {
|
||||
$ret['form'] = drupal_get_form('search_api_page_search_form', $page, $keys);
|
||||
}
|
||||
|
||||
@@ -35,14 +35,18 @@ function search_api_page_view($id, $keys = NULL) {
|
||||
watchdog('search_api_page', 'An error occurred while executing a search: !msg.', array('!msg' => $e->getMessage()), WATCHDOG_ERROR, l(t('search page'), $_GET['q']));
|
||||
}
|
||||
|
||||
// If spellcheck results are returned then add them to the render array.
|
||||
// Load spellcheck.
|
||||
if (isset($results['search_api_spellcheck'])) {
|
||||
$ret['search_api_spellcheck']['#theme'] = 'search_api_spellcheck';
|
||||
$ret['search_api_spellcheck']['#spellcheck'] = $results['search_api_spellcheck'];
|
||||
$ret['results']['#spellcheck'] = array(
|
||||
'#theme' => 'search_api_spellcheck',
|
||||
'#spellcheck' => $results['search_api_spellcheck'],
|
||||
// Let the theme function know where the key is stored by passing its arg
|
||||
// number. We can work this out from the number of args in the page path.
|
||||
$ret['search_api_spellcheck']['#options'] = array(
|
||||
'arg' => array(count(arg(NULL, $page->path))),
|
||||
'#options' => array(
|
||||
'arg' => array(count(arg(NULL, $page->path))),
|
||||
),
|
||||
'#prefix' => '<p class="search-api-spellcheck suggestion">',
|
||||
'#suffix' => '</p>',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,11 +55,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'])) {
|
||||
@@ -110,96 +115,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.
|
||||
* - $keys: The keywords of the executed search.
|
||||
*
|
||||
* @see search_api_page-results.tpl.php
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
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'];
|
||||
$results = $variables['results'];
|
||||
$items = $variables['items'];
|
||||
$keys = $variables['keys'];
|
||||
|
||||
$output = '<p class="search-performance">' . 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))) . '</p>';
|
||||
$variables['items'] = $variables['index']->loadItems(array_keys($variables['results']['results']));
|
||||
$variables['result_count'] = $results['result count'];
|
||||
$variables['sec'] = round($results['performance']['complete'], 3);
|
||||
$variables['search_performance'] = array(
|
||||
'#theme' => 'search_performance',
|
||||
'#markup' => format_plural(
|
||||
$results['result count'],
|
||||
'The search found 1 result in @sec seconds.',
|
||||
'The search found @count results in @sec seconds.',
|
||||
array('@sec' => $variables['sec'])
|
||||
),
|
||||
'#prefix' => '<p class="search-performance">',
|
||||
'#suffix' => '</p>',
|
||||
);
|
||||
|
||||
if (!$results['result count']) {
|
||||
$output .= "\n<h2>" . t('Your search yielded no results') . "</h2>\n";
|
||||
return $output;
|
||||
}
|
||||
|
||||
$output .= "\n<h2>" . t('Search results') . "</h2>\n";
|
||||
|
||||
if ($variables['view_mode'] == 'search_api_page_result') {
|
||||
$output .= '<ol class="search-results">';
|
||||
foreach ($results['results'] as $item) {
|
||||
$output .= '<li class="search-result">' . theme('search_api_page_result', array('index' => $index, 'result' => $item, 'item' => isset($items[$item['id']]) ? $items[$item['id']] : NULL, 'keys' => $keys)) . '</li>';
|
||||
}
|
||||
$output .= '</ol>';
|
||||
}
|
||||
else {
|
||||
// This option can only be set when the items are entities.
|
||||
$output .= '<div class="search-results">';
|
||||
$render = entity_view($index->item_type, $items, $variables['view_mode']);
|
||||
$output .= render($render);
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
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'];
|
||||
@@ -241,10 +216,24 @@ function theme_search_api_page_result(array $variables) {
|
||||
}
|
||||
}
|
||||
|
||||
$output = '<h3>' . ($url ? l($name, $url['path'], $url['options']) : check_plain($name)) . "</h3>\n";
|
||||
if ($text) {
|
||||
$output .= $text;
|
||||
// Check for existence. User search does not include snippets.
|
||||
$variables['snippet'] = isset($text) ? $text : '';
|
||||
|
||||
// Meta information
|
||||
global $language;
|
||||
if (isset($item->language) && $item->language != $language->language && $item->language != LANGUAGE_NONE) {
|
||||
$variables['title_attributes_array']['xml:lang'] = $item->language;
|
||||
$variables['content_attributes_array']['xml:lang'] = $item->language;
|
||||
}
|
||||
|
||||
return $output;
|
||||
$info = array();
|
||||
if (!empty($item->name)) {
|
||||
$info['user'] = $item->name;
|
||||
}
|
||||
if (!empty($item->created)) {
|
||||
$info['date'] = format_date($item->created, 'short');
|
||||
}
|
||||
// Provide separated and grouped meta information..
|
||||
$variables['info_split'] = $info;
|
||||
$variables['info'] = implode(' - ', $info);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user