addtemplate patch
http://drupal.org/node/1313676#comment-6169000 Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
@@ -60,8 +60,12 @@ function search_api_page_theme() {
|
||||
'items' => array(),
|
||||
'view_mode' => 'search_api_page_result',
|
||||
'keys' => '',
|
||||
'page_machine_name' => NULL,
|
||||
'spellcheck' => NULL,
|
||||
'pager' => NULL,
|
||||
),
|
||||
'file' => 'search_api_page.pages.inc',
|
||||
'template' => 'search-api-page-results',
|
||||
);
|
||||
$themes['search_api_page_result'] = array(
|
||||
'variables' => array(
|
||||
@@ -69,13 +73,98 @@ function search_api_page_theme() {
|
||||
'result' => NULL,
|
||||
'item' => NULL,
|
||||
'keys' => '',
|
||||
'list_classes' => '',
|
||||
),
|
||||
'file' => 'search_api_page.pages.inc',
|
||||
'template' => 'search-api-page-result',
|
||||
);
|
||||
$themes['search_performance'] = array(
|
||||
'render element' => 'element',
|
||||
);
|
||||
$themes['search_results_list'] = array(
|
||||
'render element' => 'element',
|
||||
);
|
||||
|
||||
return $themes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements theme for rendering search-performance
|
||||
*/
|
||||
function theme_search_performance($variables) {
|
||||
$element = array_shift($variables);
|
||||
|
||||
return $element['#markup'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for a list of search results.
|
||||
* Taken from theme_item_list().
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - items: An array of items to be displayed in the list. If an item is a
|
||||
* string, then it is used as is. If an item is an array, then the "data"
|
||||
* element of the array is used as the contents of the list item. If an item
|
||||
* is an array with a "children" element, those children are displayed in a
|
||||
* nested list. All other elements are treated as attributes of the list
|
||||
* item element.
|
||||
* - type: The type of list to return (e.g. "ul", "ol").
|
||||
* - attributes: The attributes applied to the list element.
|
||||
*/
|
||||
function theme_search_results_list($variables) {
|
||||
// Pull Element array from the $variables array.
|
||||
$variables = $variables['element'];
|
||||
|
||||
$items = $variables['items']; // Full data
|
||||
$type = $variables['type'];
|
||||
|
||||
// CSS classes for ul
|
||||
$attributes = (!empty($variables['attributes'])) ? $variables['attributes'] : array();
|
||||
$attributes['class'] = array_merge(
|
||||
array('item-list', 'search-results-list'),
|
||||
(isset($attributes['class'])) ? $attributes['class'] : array()
|
||||
);
|
||||
|
||||
// Render items within a list
|
||||
if (!empty($items)) {
|
||||
$output = "<$type" . drupal_attributes($attributes) . '>';
|
||||
$num_items = count($items);
|
||||
|
||||
// Parse search results as tokens to access items with full data.
|
||||
$i = 0;
|
||||
foreach ($variables['results'] as $result) {
|
||||
// Set css classes.
|
||||
$item_attributes = array();
|
||||
if ($i == 0) {
|
||||
$item_attributes['class'][] = 'first';
|
||||
}
|
||||
if ($i == $num_items - 1) {
|
||||
$item_attributes['class'][] = 'last';
|
||||
}
|
||||
(($i+1)%2) ? $item_attributes['class'][] = 'odd': $item_attributes['class'][] = 'even';
|
||||
|
||||
// Define render array.
|
||||
$data = theme(
|
||||
'search_api_page_result', array(
|
||||
'index' => $variables['index'], // Use full results index.
|
||||
'result' => $result,
|
||||
'item' => isset($items[$result['id']]) ?
|
||||
$items[$result['id']] :
|
||||
NULL,
|
||||
'keys' => $variables['keys'],
|
||||
'list_classes' => drupal_attributes($item_attributes),
|
||||
)
|
||||
);
|
||||
$output .= $data . "\n";
|
||||
$i++;
|
||||
}
|
||||
$output .= "</$type>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user