Skip to content
This repository was archived by the owner on Aug 14, 2023. It is now read-only.

Commit 1787a7c

Browse files
committed
Added the modules module_filter and Facet API
1 parent 6d08e4a commit 1787a7c

File tree

74 files changed

+15992
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+15992
-0
lines changed

sites/all/modules/contrib/facetapi/LICENSE.txt

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Hooks provided by the Current Search Blocks module.
6+
*/
7+
8+
/**
9+
* @addtogroup hooks
10+
* @{
11+
*/
12+
13+
/**
14+
* Define all current search item provided by the module.
15+
*
16+
* Current search items are elements that are added to the current search block
17+
* such as a list of active facet items, custom text, etc.
18+
*
19+
* @return array
20+
* An associative array keyed by unique name of the current search item. Each
21+
* item item is an associative array keyed by "handler" containing:
22+
* - label: The human readable name of the plugin displayed in the admin UI.
23+
* - class: The name of the plugin class.
24+
*
25+
* @see CurrentSearchItem
26+
*/
27+
function hook_current_search_items() {
28+
return array(
29+
'text' => array(
30+
'handler' => array(
31+
'label' => t('Custom text'),
32+
'class' => 'CurrentSearchItemText',
33+
),
34+
),
35+
);
36+
}
37+
38+
/**
39+
* @} End of "addtogroup hooks".
40+
*/
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Block hook implementations and block form alterations.
6+
*/
7+
8+
/**
9+
* Implements hook_form_FORM_ID_alter().
10+
*
11+
* Adds the searcher visibility settings to the block form.
12+
*/
13+
function current_search_form_block_admin_configure_alter(&$form, &$form_state) {
14+
if ('current_search' == $form['module']['#value']) {
15+
16+
$form['visibility']['current_search'] = array(
17+
'#type' => 'fieldset',
18+
'#title' => t('Search page'),
19+
'#collapsible' => TRUE,
20+
'#collapsed' => TRUE,
21+
'#group' => 'visibility',
22+
'#weight' => -5,
23+
'#attached' => array(
24+
'js' => array(drupal_get_path('module', 'current_search') . '/current_search.js'),
25+
),
26+
);
27+
28+
// Gets the default value for this block.
29+
$searcher = db_query("SELECT searcher FROM {block_current_search} WHERE delta = :delta", array(
30+
':delta' => $form['delta']['#value'],
31+
))->fetchField();
32+
33+
$form['visibility']['current_search']['searcher'] = array(
34+
'#type' => 'radios',
35+
'#title' => t('Search page'),
36+
'#options' => current_search_get_searcher_options(),
37+
'#description' => t('Select the search page this block is active on.'),
38+
'#default_value' => ($searcher) ? $searcher : current_search_get_default_searcher(),
39+
);
40+
41+
// Adds submit handler to save the searcher data.
42+
$form['#submit'][] = 'current_search_form_block_admin_configure_submit';
43+
}
44+
}
45+
46+
/**
47+
* Form submit handler for block configuration form.
48+
*
49+
* @see current_search_form_block_admin_configure_alter()
50+
*/
51+
function current_search_form_block_admin_configure_submit($form, &$form_state) {
52+
$values = $form_state['values'];
53+
current_search_set_block_searcher($values['delta'], $values['searcher']);
54+
}
55+
56+
/**
57+
* Implements hook_block_info().
58+
*/
59+
function current_search_block_info() {
60+
$blocks = array();
61+
62+
// Loads settings for enabled facets.
63+
ctools_include('export');
64+
foreach (ctools_export_crud_load_all('current_search') as $config) {
65+
if (empty($config->disabled)) {
66+
$blocks[$config->name] = array(
67+
'info' => 'Current search: ' . $config->label,
68+
'cache' => DRUPAL_NO_CACHE,
69+
);
70+
}
71+
}
72+
73+
// Returns available blocks.
74+
return $blocks;
75+
}
76+
77+
/**
78+
* Implements hook_ctools_block_info().
79+
*
80+
* @see http://drupal.org/node/1669918
81+
*/
82+
function current_search_ctools_block_info($module, $delta, &$info) {
83+
// Give the current search blocks it's own categories.
84+
$info['category'] = t('Current Search Blocks');
85+
// Allow blocks to be used before the search results in Panels.
86+
$info['render last'] = TRUE;
87+
}
88+
89+
/**
90+
* Returns the content for a facet based on the delta.
91+
*/
92+
function current_search_block_view($delta = '') {
93+
// Test block visibility.
94+
$searcher = current_search_get_block_searcher($delta);
95+
if (!current_search_check_visibility($delta)) {
96+
return;
97+
}
98+
99+
// Makes sure the adapter and configuration can be loaded.
100+
$adapter = facetapi_adapter_load($searcher);
101+
if ($adapter && ($config = ctools_export_crud_load('current_search', $delta))) {
102+
$build = array();
103+
104+
// Iterates over configs and executes the plugins.
105+
foreach ($config->settings['items'] as $name => $settings) {
106+
if ($class = ctools_plugin_load_class('current_search', 'items', $settings['id'], 'handler')) {
107+
$plugin = new $class($name, $config);
108+
if ($return = $plugin->execute($adapter)) {
109+
$build[$name] = $return;
110+
$build[$name]['#theme_wrappers'][] = 'current_search_item_wrapper';
111+
$build[$name]['#current_search_id'] = $settings['id'];
112+
$build[$name]['#current_search_name'] = $name;
113+
}
114+
}
115+
}
116+
117+
// Returns the block content.
118+
if ($build) {
119+
$build['#contextual_links'] = array(
120+
'current_search' => array('admin/config/search/current_search/list', array($delta)),
121+
);
122+
return array(
123+
'subject' => t('Current search'),
124+
'content' => $build,
125+
);
126+
}
127+
}
128+
}
129+
130+
/**
131+
* Sets the block searcher for a configuration.
132+
*
133+
* @param $name
134+
* A string containing the machine readable name of the configuration. The
135+
* name also doubles as the block delta.
136+
* @param $searcher
137+
* The machine readable name of the searcher.
138+
*/
139+
function current_search_set_block_searcher($name, $searcher) {
140+
// Deletes current search data.
141+
db_delete('block_current_search')
142+
->condition('delta', $name)
143+
->execute();
144+
145+
// Inserts new data into database.
146+
db_insert('block_current_search')
147+
->fields(array('delta', 'searcher'))
148+
->values(array(
149+
'delta' => $name,
150+
'searcher' => $searcher,
151+
))
152+
->execute();
153+
}
154+
155+
/**
156+
* Checks whether the block should be displayed.
157+
*
158+
* In cases where modules like Context are being used, hook_block_list_alter()
159+
* is not invoked and we get fatal errors. We have to test whether or not the
160+
* hook has been invoked and call this function manually otherwise.
161+
*
162+
* @param $delta
163+
* The block delta.
164+
*
165+
* @return
166+
* A boolean flagging whether to display this block or not.
167+
*/
168+
function current_search_check_visibility($delta) {
169+
$searcher = current_search_get_block_searcher($delta);
170+
171+
// Checks whether block should be displayed.
172+
if (!facetapi_is_active_searcher($searcher)) {
173+
return FALSE;
174+
}
175+
if (!$adapter = facetapi_adapter_load($searcher)) {
176+
return FALSE;
177+
}
178+
if (!$adapter->searchExecuted($searcher)) {
179+
return FALSE;
180+
}
181+
if (!$config = current_search_item_load($delta)) {
182+
return FALSE;
183+
}
184+
185+
// Returns TRUE based on the empty_searches setting and the current search.
186+
switch ($config->settings['advanced']['empty_searches']) {
187+
case CURRENT_SEARCH_DISPLAY_KEYS:
188+
return ($adapter->getSearchKeys());
189+
case CURRENT_SEARCH_DISPLAY_FILTERS:
190+
return ($adapter->getAllActiveItems());
191+
case CURRENT_SEARCH_DISPLAY_KEYS_FILTERS:
192+
return ($adapter->getSearchKeys() || $adapter->getAllActiveItems());
193+
case CURRENT_SEARCH_DISPLAY_ALWAYS:
194+
default:
195+
return TRUE;
196+
}
197+
}
198+
199+
/**
200+
* Gets the searcher associated with the delta.
201+
*
202+
* @param string $delta
203+
* The block delta.
204+
*
205+
* @return string
206+
* The machine name of the searcher associated with the block.
207+
*/
208+
function current_search_get_block_searcher($delta) {
209+
$map = &drupal_static('current_search_delta_map');
210+
if (NULL === $map) {
211+
$map = array();
212+
$result = db_query('SELECT delta, searcher FROM {block_current_search}');
213+
foreach ($result as $record) {
214+
$map[$record->delta] = $record->searcher;
215+
}
216+
}
217+
if (!isset($map[$delta])) {
218+
$map[$delta] = current_search_get_default_searcher();
219+
}
220+
return $map[$delta];
221+
}
222+
223+
/**
224+
* Gets the default searcher.
225+
*
226+
* @return
227+
* The default searcher.
228+
*
229+
* @todo Figure out a beter default system.
230+
*/
231+
function current_search_get_default_searcher() {
232+
$options = current_search_get_searcher_options();
233+
return key($options);
234+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
.current-search-setting {
3+
float: left;
4+
display: inline;
5+
}
6+
7+
.current-search-plugin {
8+
margin-right: 2em;
9+
}
10+
11+
.current-search-label {
12+
margin-right: 3em;
13+
}
14+
15+
.current-search-plugin label, .current-search-label label {
16+
display: inline-block;
17+
}
18+
19+
.current-search-button .form-actions {
20+
margin-top: .4em;
21+
}
22+
23+
.current-search-remove-link {
24+
text-align: center;
25+
}
26+
27+
.current-search-group-title {
28+
display: inline;
29+
font-weight: bold;
30+
}
31+
32+
.current-search-item-group .item-list {
33+
display: inline-block;
34+
}
35+
36+
.region-content .current-search-item-group .item-list,
37+
.region-highlighted .current-search-item-group .item-list,
38+
.region-help .current-search-item-group .item-list {
39+
margin-left: -1.5em;
40+
}
41+
42+
.form-actions {
43+
float: right;
44+
margin-top: 0;
45+
margin-bottom: 0;
46+
}
47+
48+
.current-search-description {
49+
margin-top: .5em;
50+
margin-bottom: 1em;
51+
}

0 commit comments

Comments
 (0)