-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.module
45 lines (40 loc) · 1.3 KB
/
example.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
// Path of our panel.
define('EXMPLE_PATH', 'example');
/**
* Implements hook_ajax_render_alter().
*/
function example_ajax_render_alter(&$commands) {
if ($_GET['q'] != EXMPLE_PATH) {
return;
}
// Facets that present on the page.
$facet_delta = array('apache_solr_index_author_name', 'apache_solr_index_type');
foreach ($facet_delta as $delta) {
// Load block for facet.
$block_array = search_api_facets_block_view($delta);
$delta_class = str_replace('_', '-', $delta);
// Render block.
$output = drupal_render($block_array);
// Show or hide block.
if (!empty($output)) {
$commands[] = ajax_command_invoke('.pane-search-api-facets-' . $delta_class, 'show');
$commands[] = ajax_command_replace('.pane-search-api-facets-' . $delta_class . ' .pane-content .item-list', $output);
}
else {
$commands[] = ajax_command_invoke('.pane-search-api-facets-' . $delta_class, 'hide');
}
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function example_form_views_exposed_form_alter(&$form, &$form_state) {
if ($_GET['q'] != EXMPLE_PATH) {
return;
}
// Add action to form so it will work without javascript.
$form['#action'] = EXMPLE_PATH;
// Add javascript for facets.
drupal_add_js(drupal_get_path('module', 'example') . '/example.js');
}