- Patch #164032 by Crell, Chris Kennedy, dmitrig01, WimLeers, dvessel et al: tpl-ified the search module.
parent
9a9ea37403
commit
6c85fdc6ab
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file search-block-form.tpl.php
|
||||
* Default theme implementation for displaying a search form within a block region.
|
||||
*
|
||||
* Available variables:
|
||||
* - $search_form: The complete search form ready for print.
|
||||
* - $search: Array of keyed search elements. Can be used to print each form
|
||||
* element separately.
|
||||
*
|
||||
* Default keys within $search:
|
||||
* - $search['search_block_form']: Text input area wrapped in a div.
|
||||
* - $search['submit']: Form submit button.
|
||||
* - $search['hidden']: Hidden form elements. Used to validate forms when submitted.
|
||||
*
|
||||
* Since $search is keyed, a direct print of the form element is possible.
|
||||
* Modules can add to the search form so it is recommended to check for their
|
||||
* existance before printing. The default keys will always exist.
|
||||
*
|
||||
* <?php if (isset($search['extra_field'])): ?>
|
||||
* <div class="extra-field">
|
||||
* <?php print $search['extra_field']; ?>
|
||||
* </div>
|
||||
* <?php endif; ?>
|
||||
*
|
||||
* To check for all available data within $search, use the code below.
|
||||
*
|
||||
* <?php print '<pre>'. check_plain(print_r($search, 1)) .'</pre>'; ?>
|
||||
*
|
||||
* @see template_preprocess_search_block_form()
|
||||
*/
|
||||
?>
|
||||
<div class="container-inline">
|
||||
<?php print $search_form; ?>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file search-result.tpl.php
|
||||
* Default theme implementation for displaying a single search result.
|
||||
*
|
||||
* This template renders a single search result and is collected into
|
||||
* search-results.tpl.php. This and the parent template are
|
||||
* dependent to one another sharing the markup for definition lists.
|
||||
*
|
||||
* Available variables:
|
||||
* - $url: URL of the result.
|
||||
* - $title: Title of the result.
|
||||
* - $snippet: A small preview of the result. Does not apply to user searches.
|
||||
* - $info: String of all the meta information ready for print. Does not apply
|
||||
* to user searches.
|
||||
* - $info_split: Contains same data as $info split into a keyed array.
|
||||
* - $type: The type of search, e.g., "node" or "user".
|
||||
*
|
||||
* Default keys within $info_split:
|
||||
* - $info_split['type']: Node type.
|
||||
* - $info_split['user']: Author of the node linked to users profile. Depends
|
||||
* on permission.
|
||||
* - $info_split['date']: Last update of the node. Short formatted.
|
||||
* - $info_split['comment']: Number of comments output as "% comments", %
|
||||
* being the count. Depends on comment.module.
|
||||
* - $info_split['upload']: Number of attachments output as "% attachments", %
|
||||
* being the count. Depends on upload.module.
|
||||
*
|
||||
* Since $info_split is keyed, a direct print of the item is possible.
|
||||
* This array does not apply to user searches so it is recommended to check
|
||||
* for their existance before printing. The default keys of 'type', 'user' and
|
||||
* 'date' always exist for node searches. Modules may provide other data.
|
||||
*
|
||||
* <?php if (isset($info_split['comment'])) : ?>
|
||||
* <span class="info-comment">
|
||||
* <?php print $info_split['comment']; ?>
|
||||
* </span>
|
||||
* <?php endif; ?>
|
||||
*
|
||||
* To check for all available data within $info_split, use the code below.
|
||||
*
|
||||
* <?php print '<pre>'. check_plain(print_r($info_split, 1)) .'</pre>'; ?>
|
||||
*
|
||||
* @see template_preprocess_search_result()
|
||||
*/
|
||||
?>
|
||||
<dt class="title">
|
||||
<a href="<?php print $url; ?>"><?php print $title; ?></a>
|
||||
</dt>
|
||||
<dd>
|
||||
<?php if ($snippet) : ?>
|
||||
<p class="search-snippet"><?php print $snippet; ?></p>
|
||||
<?php endif; ?>
|
||||
<?php if ($info) : ?>
|
||||
<p class="search-info"><?php print $info; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file search-results.tpl.php
|
||||
* Default theme implementation for displaying search results.
|
||||
*
|
||||
* This template collects each invocation of theme_search_result(). This and
|
||||
* the child template are dependant to one another sharing the markup for
|
||||
* definition lists.
|
||||
*
|
||||
* Note that modules may implement their own search type and theme function
|
||||
* completely bypassing this template.
|
||||
*
|
||||
* Available variables:
|
||||
* - $search_results: All results as it is rendered through
|
||||
* search-result.tpl.php
|
||||
* - $type: The type of search, e.g., "node" or "user".
|
||||
*
|
||||
*
|
||||
* @see template_preprocess_search_results()
|
||||
*/
|
||||
?>
|
||||
<dl class="search-results <?php print $type; ?>-results">
|
||||
<?php print $search_results; ?>
|
||||
</dl>
|
||||
<?php print $pager; ?>
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file search-theme-form.tpl.php
|
||||
* Default theme implementation for displaying a search form directly into the
|
||||
* theme layout. Not to be confused with the search block or the search page.
|
||||
*
|
||||
* Available variables:
|
||||
* - $search_form: The complete search form ready for print.
|
||||
* - $search: Array of keyed search elements. Can be used to print each form
|
||||
* element separately.
|
||||
*
|
||||
* Default keys within $search:
|
||||
* - $search['search_theme_form']: Text input area wrapped in a div.
|
||||
* - $search['submit']: Form submit button.
|
||||
* - $search['hidden']: Hidden form elements. Used to validate forms when submitted.
|
||||
*
|
||||
* Since $search is keyed, a direct print of the form element is possible.
|
||||
* Modules can add to the search form so it is recommended to check for their
|
||||
* existance before printing. The default keys will always exist.
|
||||
*
|
||||
* <?php if (isset($search['extra_field'])): ?>
|
||||
* <div class="extra-field">
|
||||
* <?php print $search['extra_field']; ?>
|
||||
* </div>
|
||||
* <?php endif; ?>
|
||||
*
|
||||
* To check for all available data within $search, use the code below.
|
||||
*
|
||||
* <?php print '<pre>'. check_plain(print_r($search, 1)) .'</pre>'; ?>
|
||||
*
|
||||
* @see template_preprocess_search_theme_form()
|
||||
*/
|
||||
?>
|
||||
<div id="search" class="container-inline">
|
||||
<?php print $search_form; ?>
|
||||
</div>
|
||||
|
|
@ -3,12 +3,6 @@
|
|||
.search-form {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
.search-form p {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0.2em;
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
.search-form input {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
|
|
|
|||
|
|
@ -118,17 +118,21 @@ function search_theme() {
|
|||
return array(
|
||||
'search_theme_form' => array(
|
||||
'arguments' => array('form' => NULL),
|
||||
'template' => 'search-theme-form',
|
||||
),
|
||||
'search_block_form' => array(
|
||||
'arguments' => array('form' => NULL),
|
||||
'template' => 'search-block-form',
|
||||
),
|
||||
'search_item' => array(
|
||||
'arguments' => array('item' => NULL, 'type' => NULL),
|
||||
'search_result' => array(
|
||||
'arguments' => array('result' => NULL, 'type' => NULL),
|
||||
'file' => 'search.pages.inc',
|
||||
'template' => 'search-result',
|
||||
),
|
||||
'search_page' => array(
|
||||
'search_results' => array(
|
||||
'arguments' => array('results' => NULL, 'type' => NULL),
|
||||
'file' => 'search.pages.inc',
|
||||
'template' => 'search-results',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
@ -940,8 +944,7 @@ function search_form(&$form_state, $action = '', $keys = '', $type = NULL, $prom
|
|||
* @see theme_search_box_form().
|
||||
*/
|
||||
function search_box(&$form_state, $form_id) {
|
||||
// Use search_keys instead of keys to avoid ID conflicts with the search block.
|
||||
$form[$form_id .'_keys'] = array(
|
||||
$form[$form_id] = array(
|
||||
'#title' => t('Search this site'),
|
||||
'#type' => 'textfield',
|
||||
'#size' => 15,
|
||||
|
|
@ -960,25 +963,61 @@ function search_box(&$form_state, $form_id) {
|
|||
*/
|
||||
function search_box_form_submit($form, &$form_state) {
|
||||
$form_id = $form['form_id']['#value'];
|
||||
$form_state['redirect'] = 'search/node/'. trim($form_state['values'][$form_id .'_keys']);
|
||||
$form_state['redirect'] = 'search/node/'. trim($form_state['values'][$form_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme the theme search form.
|
||||
* Process variables for search-theme-form.tpl.php.
|
||||
*
|
||||
* @ingroup themeable
|
||||
* The $variables array contains the following arguments:
|
||||
* - $form
|
||||
*
|
||||
* @see search-theme-form.tpl.php
|
||||
*/
|
||||
function theme_search_theme_form($form) {
|
||||
return '<div id="search" class="container-inline">'. drupal_render($form) .'</div>';
|
||||
function template_preprocess_search_theme_form(&$variables) {
|
||||
$variables['search'] = array();
|
||||
$hidden = array();
|
||||
// Provide variables named after form keys so themers can print each element independently.
|
||||
foreach (element_children($variables['form']) as $key) {
|
||||
$type = $variables['form'][$key]['#type'];
|
||||
if ($type == 'hidden' || $type == 'token') {
|
||||
$hidden[] = drupal_render($variables['form'][$key]);
|
||||
}
|
||||
else {
|
||||
$variables['search'][$key] = drupal_render($variables['form'][$key]);
|
||||
}
|
||||
}
|
||||
// Hidden form elements have no value to themers. No need for separation.
|
||||
$variables['search']['hidden'] = implode($hidden);
|
||||
// Collect all form elements to make it easier to print the whole form.
|
||||
$variables['search_form'] = implode($variables['search']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme the block search form.
|
||||
* Process variables for search-block-form.tpl.php.
|
||||
*
|
||||
* @ingroup themeable
|
||||
* The $variables array contains the following arguments:
|
||||
* - $form
|
||||
*
|
||||
* @see search-block-form.tpl.php
|
||||
*/
|
||||
function theme_search_block_form($form) {
|
||||
return '<div class="container-inline">'. drupal_render($form) .'</div>';
|
||||
function template_preprocess_search_block_form(&$variables) {
|
||||
$variables['search'] = array();
|
||||
$hidden = array();
|
||||
// Provide variables named after form keys so themers can print each element independently.
|
||||
foreach (element_children($variables['form']) as $key) {
|
||||
$type = $variables['form'][$key]['#type'];
|
||||
if ($type == 'hidden' || $type == 'token') {
|
||||
$hidden[] = drupal_render($variables['form'][$key]);
|
||||
}
|
||||
else {
|
||||
$variables['search'][$key] = drupal_render($variables['form'][$key]);
|
||||
}
|
||||
}
|
||||
// Hidden form elements have no value to themers. No need for separation.
|
||||
$variables['search']['hidden'] = implode($hidden);
|
||||
// Collect all form elements to make it easier to print the whole form.
|
||||
$variables['search_form'] = implode($variables['search']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -994,7 +1033,7 @@ function search_data($keys = NULL, $type = 'node') {
|
|||
return module_invoke($type, 'search_page', $results);
|
||||
}
|
||||
else {
|
||||
return theme('search_page', $results, $type);
|
||||
return theme('search_results', $results, $type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,63 +50,58 @@ function search_view($type = 'node') {
|
|||
}
|
||||
|
||||
/**
|
||||
* Format the result page of a search query.
|
||||
* Process variables for search-results.tpl.php.
|
||||
*
|
||||
* Modules may implement hook_search_page() in order to override this default
|
||||
* function to display search results. In that case it is expected they provide
|
||||
* their own themeable functions.
|
||||
* The $variables array contains the following arguments:
|
||||
* - $results
|
||||
* - $type
|
||||
*
|
||||
* @param $results
|
||||
* All search result as returned by hook_search().
|
||||
* @param $type
|
||||
* The type of item found, such as "user" or "node".
|
||||
*
|
||||
* @ingroup themeable
|
||||
* @see search-results.tpl.php
|
||||
*/
|
||||
function theme_search_page($results, $type) {
|
||||
$output = '<dl class="search-results">';
|
||||
|
||||
foreach ($results as $entry) {
|
||||
$output .= theme('search_item', $entry, $type);
|
||||
function template_preprocess_search_results(&$variables) {
|
||||
$variables['search_results'] = '';
|
||||
foreach ($variables['results'] as $result) {
|
||||
$variables['search_results'] .= theme('search_result', $result, $variables['type']);
|
||||
}
|
||||
$output .= '</dl>';
|
||||
$output .= theme('pager', NULL, 10, 0);
|
||||
|
||||
return $output;
|
||||
$variables['pager'] = theme('pager', NULL, 10, 0);
|
||||
// Provide alternate search results template.
|
||||
$variables['template_files'][] = 'search-results-'. $variables['type'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format a single result entry of a search query. This function is normally
|
||||
* called by theme_search_page() or hook_search_page().
|
||||
* Process variables for search-result.tpl.php.
|
||||
*
|
||||
* @param $item
|
||||
* A single search result as returned by hook_search(). The result should be
|
||||
* an array with keys "link", "title", "type", "user", "date", and "snippet".
|
||||
* Optionally, "extra" can be an array of extra info to show along with the
|
||||
* result.
|
||||
* @param $type
|
||||
* The type of item found, such as "user" or "node".
|
||||
* The $variables array contains the following arguments:
|
||||
* - $result
|
||||
* - $type
|
||||
*
|
||||
* @ingroup themeable
|
||||
* @see search-result.tpl.php
|
||||
*/
|
||||
function theme_search_item($item, $type) {
|
||||
$output = ' <dt class="title"><a href="'. check_url($item['link']) .'">'. check_plain($item['title']) .'</a></dt>';
|
||||
function template_preprocess_search_result(&$variables) {
|
||||
$result = $variables['result'];
|
||||
$variables['url'] = check_url($result['link']);
|
||||
$variables['title'] = check_plain($result['title']);
|
||||
|
||||
$info = array();
|
||||
if (!empty($item['type'])) {
|
||||
$info[] = $item['type'];
|
||||
if (!empty($result['type'])) {
|
||||
$info['type'] = $result['type'];
|
||||
}
|
||||
if (!empty($item['user'])) {
|
||||
$info[] = $item['user'];
|
||||
if (!empty($result['user'])) {
|
||||
$info['user'] = $result['user'];
|
||||
}
|
||||
if (!empty($item['date'])) {
|
||||
$info[] = format_date($item['date'], 'small');
|
||||
if (!empty($result['date'])) {
|
||||
$info['date'] = format_date($result['date'], 'small');
|
||||
}
|
||||
if (isset($item['extra']) && is_array($item['extra'])) {
|
||||
$info = array_merge($info, $item['extra']);
|
||||
if (isset($result['extra']) && is_array($result['extra'])) {
|
||||
$info = array_merge($info, $result['extra']);
|
||||
}
|
||||
$output .= ' <dd>'. (!empty($item['snippet']) ? '<p>'. $item['snippet'] .'</p>' : '') .'<p class="search-info">'. implode(' - ', $info) .'</p></dd>';
|
||||
return $output;
|
||||
// Check for existence. User search does not include snippets.
|
||||
$variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : '';
|
||||
// Provide separated and grouped meta information..
|
||||
$variables['info_split'] = $info;
|
||||
$variables['info'] = implode(' - ', $info);
|
||||
// Provide alternate search result template.
|
||||
$variables['template_files'][] = 'search-result-'. $variables['type'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -133,4 +128,3 @@ function search_form_submit($form, &$form_state) {
|
|||
$form_state['redirect'] = 'search/'. $type .'/'. $keys;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue