function ctools_search_result_content_type_render
Render the custom content type.
File
-
plugins/
content_types/ search/ search_result.inc, line 37
Code
function ctools_search_result_content_type_render($subtype, $conf, $panel_args, $context) {
$search_info = search_get_info();
if (empty($search_info[$conf['type']])) {
return;
}
$info = $search_info[$conf['type']];
$keys = NULL;
if (!empty($context) && isset($context->data)) {
$keys = $context->data;
}
$conditions = NULL;
if (isset($info['conditions_callback']) && function_exists($info['conditions_callback'])) {
// Build an optional array of more search conditions.
$conditions = $info['conditions_callback']($keys);
}
// Display nothing at all if no keywords were entered.
if (empty($keys) && empty($conditions)) {
if (!empty($conf['override_no_key'])) {
$block->title = $conf['no_key_title'];
$block->content = check_markup($conf['no_key'], $conf['no_key_format'], FALSE);
return $block;
}
return;
}
// Build the content type block.
$block = new stdClass();
$block->module = 'search';
$block->delta = 'result';
$results = '';
// Only search if there are keywords or non-empty conditions.
if ($keys || !empty($conditions)) {
// Collect the search results.
$results = search_data($keys, $info['module'], $conditions);
// A workaround for ApacheSolr.
// @todo see http://drupal.org/node/1343142#comment-5495248
// This workaround is to be removed when a better one can be written.
if (!empty($results['search_results']['#results'])) {
$results['#results'] = $results['search_results']['#results'];
}
}
if (!empty($conf['log'])) {
// Log the search keys:
watchdog('search', 'Searched %type for %keys.', array(
'%keys' => $keys,
'%type' => $info['title'],
), WATCHDOG_NOTICE, l(t('results'), $_GET['q']));
}
if (!empty($results['#results'])) {
$output = "<ol class=\"search-results {$conf['type']}-results\">\n";
foreach ($results['#results'] as $result) {
$output .= theme('search_result', array(
'result' => $result,
'module' => $conf['type'],
));
}
$output .= "</ol>\n";
$output .= theme('pager', array(
'tags' => NULL,
));
$block->title = t('Search results');
$block->content = $output;
}
else {
if (empty($conf['override_empty'])) {
$block->title = t('Your search yielded no results');
$block->content = search_help('search#noresults', drupal_help_arg());
}
else {
$block->title = $conf['empty_title'];
$block->content = check_markup($conf['empty'], $conf['empty_format'], FALSE);
}
}
return $block;
}