Last active
August 29, 2015 14:23
-
-
Save labboy0276/77711056ba2054d133f6 to your computer and use it in GitHub Desktop.
Panels Everywhere + Default Search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install the page_manager_search && search combine, set it up as you please but use search_combine as default. | |
Create a variant in the site_template for the search, set it to be above the default one. Use a selection for path URL sites/all/* on the string. | |
To render the default search_view as a block use: | |
/** | |
* Implements hook_block_info(). | |
*/ | |
function YOURMODULE_block_info() { | |
$blocks = array(); | |
$blocks['search'] = array( | |
'info' => t('Search View / Results Render'), | |
); | |
return $blocks; | |
} | |
/** | |
* Implements hook_block_view(). | |
*/ | |
function YOURMODULE_block_view($delta='') { | |
$block = array(); | |
switch($delta) { | |
case 'search' : | |
$block['content'] = YOURMODULE_search_view_render(); | |
break; | |
} | |
return $block; | |
} | |
/** | |
* Custom function to assemble the search_view as a block. | |
* I am doing this because the panels search version doesn't work well with Panels Everywhere. | |
* | |
* @return | |
* returns a renderable array of block content. | |
*/ | |
function YOURMODULE_search_view_render() { | |
// Include the render page so we can use it and its template functions. | |
module_load_include('inc', 'search', 'search.pages'); | |
// So we can use the path auto methods | |
module_load_include('inc', 'pathauto', 'pathauto'); | |
// Get the url so we can parse it in a second. | |
$url = request_uri(); | |
// Get the query for pagination and strip it | |
$query = preg_replace('/\?.*/', '', $url); | |
$key = explode('/', $query); | |
// Break the url param down and fix it with path auto clean string. | |
$term = urldecode(end($key)); | |
$termfix = pathauto_cleanstring($term); | |
// Remove the pathauto hyphens. | |
$searchterm = str_replace('-', ' ', $termfix); | |
// Call it and render it. | |
$view = search_view('search_combine', $searchterm); | |
$block = drupal_render($view); | |
return $block; | |
} | |
I also added the search-result.tpl.php + search-results.tpl.php and edited them to the clients mockups | |
Also I need to change the results to diplay totals: | |
in template.php | |
/** | |
* Implements template_preprocess_search_results(). | |
* Borrowed the search results from lullabot: | |
* https://www.lullabot.com/blog/article/display-count-search-results-drupal-7 | |
*/ | |
function YOURTHEME_preprocess_search_results(&$vars) { | |
if (isset($GLOBALS['pager_total_items'])) { | |
// search.module shows 10 items per page (this isn't customizable) | |
$itemsPerPage = 10; | |
// Determine which page is being viewed | |
// If $_REQUEST['page'] is not set, we are on page 1 | |
$currentPage = (isset($_REQUEST['page']) ? $_REQUEST['page'] : 0) + 1; | |
// Get the total number of results from the global pager | |
$total = $GLOBALS['pager_total_items'][0]; | |
// Determine which results are being shown ("Showing results x through y") | |
$start = (10 * $currentPage) - 9; | |
// If on the last page, only go up to $total, not the total that COULD be | |
// shown on the page. This prevents things like "Displaying 11-20 of 17". | |
$end = (($itemsPerPage * $currentPage) >= $total) ? $total : ($itemsPerPage * $currentPage); | |
// If there is more than one page of results: | |
if ($total > $itemsPerPage) { | |
$vars['search_totals'] = t('Displaying !start - !end of !total results', array( | |
'!start' => $start, | |
'!end' => $end, | |
'!total' => $total, | |
)); | |
} | |
else { | |
// Only one page of results, so make it simpler | |
$vars['search_totals'] = t('Displaying !total !results_label', array( | |
'!total' => $total, | |
// Be smart about labels: show "result" for one, "results" for multiple | |
'!results_label' => format_plural($total, 'result', 'results'), | |
)); | |
} | |
} | |
} | |
Now you can so what you need to the default search page and have more control of the output, etc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment