From 6c85fdc6ab6934eea9821f02b89ef395a7cb4d06 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 31 Oct 2007 18:06:38 +0000 Subject: - Patch #164032 by Crell, Chris Kennedy, dmitrig01, WimLeers, dvessel et al: tpl-ified the search module. --- modules/search/search-block-form.tpl.php | 37 +++++++++++++++ modules/search/search-result.tpl.php | 59 +++++++++++++++++++++++ modules/search/search-results.tpl.php | 27 +++++++++++ modules/search/search-theme-form.tpl.php | 38 +++++++++++++++ modules/search/search.css | 6 --- modules/search/search.module | 69 +++++++++++++++++++++------ modules/search/search.pages.inc | 80 +++++++++++++++----------------- 7 files changed, 252 insertions(+), 64 deletions(-) create mode 100644 modules/search/search-block-form.tpl.php create mode 100644 modules/search/search-result.tpl.php create mode 100644 modules/search/search-results.tpl.php create mode 100644 modules/search/search-theme-form.tpl.php (limited to 'modules') diff --git a/modules/search/search-block-form.tpl.php b/modules/search/search-block-form.tpl.php new file mode 100644 index 000000000..a464765a9 --- /dev/null +++ b/modules/search/search-block-form.tpl.php @@ -0,0 +1,37 @@ + + *
+ * + *
+ * + * + * To check for all available data within $search, use the code below. + * + * '. check_plain(print_r($search, 1)) .''; ?> + * + * @see template_preprocess_search_block_form() + */ +?> +
+ +
diff --git a/modules/search/search-result.tpl.php b/modules/search/search-result.tpl.php new file mode 100644 index 000000000..3a82870d0 --- /dev/null +++ b/modules/search/search-result.tpl.php @@ -0,0 +1,59 @@ + + * + * + * + * + * + * To check for all available data within $info_split, use the code below. + * + * '. check_plain(print_r($info_split, 1)) .''; ?> + * + * @see template_preprocess_search_result() + */ +?> +
+ +
+
+ +

+ + +

+ +
diff --git a/modules/search/search-results.tpl.php b/modules/search/search-results.tpl.php new file mode 100644 index 000000000..709245b26 --- /dev/null +++ b/modules/search/search-results.tpl.php @@ -0,0 +1,27 @@ + +
+ +
+ diff --git a/modules/search/search-theme-form.tpl.php b/modules/search/search-theme-form.tpl.php new file mode 100644 index 000000000..541b498b4 --- /dev/null +++ b/modules/search/search-theme-form.tpl.php @@ -0,0 +1,38 @@ + + *
+ * + *
+ * + * + * To check for all available data within $search, use the code below. + * + * '. check_plain(print_r($search, 1)) .''; ?> + * + * @see template_preprocess_search_theme_form() + */ +?> + diff --git a/modules/search/search.css b/modules/search/search.css index 7ca52dd2e..cb4a22025 100644 --- a/modules/search/search.css +++ b/modules/search/search.css @@ -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; diff --git a/modules/search/search.module b/modules/search/search.module index cf52bc2d6..246f95f22 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -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 ''; +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. + * + * The $variables array contains the following arguments: + * - $form * - * @ingroup themeable + * @see search-block-form.tpl.php */ -function theme_search_block_form($form) { - return '
'. drupal_render($form) .'
'; +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); } } } diff --git a/modules/search/search.pages.inc b/modules/search/search.pages.inc index e54e7af7e..f566223ec 100644 --- a/modules/search/search.pages.inc +++ b/modules/search/search.pages.inc @@ -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 = '
'; - - 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 .= '
'; - $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 = '
'. check_plain($item['title']) .'
'; +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 .= '
'. (!empty($item['snippet']) ? '

'. $item['snippet'] .'

' : '') .'

'. implode(' - ', $info) .'

'; - 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; } - -- cgit v1.2.3