Last active
December 29, 2015 10:19
-
-
Save soulston/7656252 to your computer and use it in GitHub Desktop.
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
THEME FUNCTION | |
function ln_funnelback_theme() { | |
return array( | |
'ln_funnelback_results' => array( | |
'arguments' => array('results' => NULL, 'pager' => NULL), | |
'template' => 'ln_funnelback_results', | |
), | |
'ln_funnelback_contextual_nav_block' => array( | |
'arguments' => array('summary' => NULL, 'contextual_nav' => NULL), | |
'template' => 'ln_funnelback_contextual_nav_block', | |
), | |
'ln_funnelback_pager' => array( | |
'arguments' => array('summary' => NULL), | |
'template' => 'ln_funnelback_pager', | |
), | |
'ln_funnelback_facets_block' => array( | |
'arguments' => array('request_params' => NULL, 'selected_facets' => NULL, 'querystring' => NULL, 'facets' => NULL), | |
'template' => 'ln_funnelback_facets_block', | |
), | |
); | |
} | |
/** | |
* Implements hook_block_view(). | |
*/ | |
function ln_funnelback_block_view($delta = '') { | |
$block = array(); | |
switch ($delta) { | |
case 'search_form': | |
if (user_access('use ln funnelback search')) { | |
$block['subject'] = t(''); | |
$block['content'] = drupal_get_form('ln_funnelback_search_block_form'); | |
} | |
break; | |
case 'contextual': | |
if (user_access('use ln funnelback search')) { | |
$block['subject'] = t('Context'); | |
$block['content'] = ln_funnelback_contextual_nav_view(); | |
} | |
break; | |
case 'facets': | |
if (user_access('use ln funnelback search')) { | |
$block['subject'] = t('Facets'); | |
$block['content'] = ln_funnelback_facets_view(); | |
} | |
break; | |
} | |
return $block; | |
} | |
/** | |
* Block callback for facets. | |
*/ | |
function ln_funnelback_facets_view() { | |
$query = filter_xss($_GET['query']); | |
$start = (!empty($_GET['start'])) ? filter_xss($_GET['start']) : 0; | |
$request_data = _build_fb_request(); | |
// Set the data to send to ln_funnelback_request. | |
$request_params = $request_data['request_params']; | |
$base_url = $request_data['base_url']; | |
$api_path = $request_data['api_path']; | |
// Allow modules to modify the query parameters. | |
drupal_alter('ln_funnelback_query', $request_params); | |
$response = ln_funnelback_request($base_url, $api_path, $request_params); | |
if ($response->code == 200) { | |
$json = drupal_json_decode($response->data); | |
} | |
$selected_facets = $json['question']['selectedFacets']; | |
$querystring = $json['QueryString']; | |
$facets = $json['response']['facets']; | |
// See question > selectedFacets | |
// See question > selectedCatgoryValues | |
// Need to pass the selected facet information so we can | |
// let users reset - this may need to be looked at for nested facets. | |
// In that case you would need to check you were at the deepest level. | |
// pass an array of all the url parameters so that the facet code can decide what needs outputting | |
$output = theme('ln_funnelback_facets_block', array( | |
'request_params' => $request_params, | |
'selected_facets' => $selected_facets, | |
'querystring' => $querystring, | |
'facets' => $facets, | |
)); | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment