search_view
- Versions
- 4.6 – 5
search_view()- 6 – 7
search_view($type = 'node')
Menu callback; presents the search form and/or search results.
Code
modules/search/search.pages.inc, line 11
<?php
function search_view($type = 'node') {
// Search form submits with POST but redirects to GET. This way we can keep
// the search query URL clean as a whistle:
// search/type/keyword+keyword
if (!isset($_POST['form_id'])) {
if ($type == '') {
// Note: search/node can not be a default tab because it would take on the
// path of its parent (search). It would prevent remembering keywords when
// switching tabs. This is why we drupal_goto to it from the parent instead.
drupal_goto('search/node');
}
$keys = search_get_keys();
// Only perform search if there is non-whitespace search term:
$results = '';
if (trim($keys)) {
// Log the search keys:
watchdog('search', '%keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name')), WATCHDOG_NOTICE, l(t('results'), 'search/' . $type . '/' . $keys));
// Collect the search results:
$results = search_data($keys, $type);
// Construct the search form.
$build['search_form'] = drupal_get_form('search_form', NULL, $keys, $type);
$build['search_results'] = array(
'#theme' => 'search_results_listing',
'#title' => empty($results) ? t('Your search yielded no results') : t('Search results'),
'#content' => empty($results) ? search_help('search#noresults', drupal_help_arg()) : $results,
);
return $build;
}
}
return drupal_get_form('search_form', NULL, empty($keys) ? '' : $keys, $type);
}
?>Login or register to post comments 