forked from discoverygarden/islandora_collection_search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathislandora_collection_search.module
137 lines (125 loc) · 4.22 KB
/
islandora_collection_search.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* @file
* Miscellaneous hook implementations.
*/
/**
* Implements hook_block_info().
*/
function islandora_collection_search_block_info() {
$blocks['islandora_collection_search'] = array(
'info' => t('Islandora Collection Search'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function islandora_collection_search_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'islandora_collection_search':
if (user_access('search islandora solr')) {
module_load_include('inc', 'islandora_collection_search', 'includes/search.form');
$block['subject'] = t('Islandora Collection Search');
$block['content'] = drupal_get_form('islandora_collection_search_form');
}
break;
}
return $block;
}
/**
* Implements hook_islandora_solr_query().
*
* Adds a collection as a filter if it is defined in the url params.
*/
function islandora_collection_search_islandora_solr_query($islandora_solr_query) {
// Exit early if the collection pid isn't set in the url params.
if (!isset($_GET['cp'])) {
return;
}
// Grab the collection pid and add it as a solr query filter.
$collection_pid = $_GET['cp'];
$ancestor_field = variable_get('islandora_collection_search_ancestor_field', 'ancestors_ms');
$filter = format_string('!field:"!value"', array(
'!field' => $ancestor_field,
'!value' => $collection_pid,
));
$islandora_solr_query->solrParams['fq'][] = $filter;
}
/**
* Implements hook_form_alter().
*
* Adds a submit handler to any form that can potentially alter the object
* hierarchy (e.g. changing parents, etc...).
*/
function islandora_collection_search_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'islandora_basic_collection_migrate_children_form':
case 'islandora_basic_collection_share_children_form':
case 'islandora_basic_collection_delete_children_form':
$form['#submit'][] = 'islandora_collection_search_collection_form_submit';
break;
}
}
/**
* Implements hook_menu().
*/
function islandora_collection_search_menu() {
$items = array();
$items['admin/islandora/tools/collection_search'] = array(
'title' => 'Collection Search',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_collection_search_admin_form'),
'access arguments' => array('administer site configuration'),
'file' => 'includes/admin.form.inc',
);
return $items;
}
/**
* Re-indexes all children of the object(s) manipulated by a form.
*
* @param array $form
* Array of drupal form api elements.
* @param array $form_state
* Array representing the form state.
*/
function islandora_collection_search_collection_form_submit(&$form, &$form_state) {
// Grab the initial list of children that are being migrated from the form.
$children = array_keys(array_filter($form_state['values']['children']));
module_load_include('inc', 'islandora_collection_search', 'includes/batch');
batch_set(islandora_collection_search_reindex_descendants_batch($children));
}
/**
* Implements hook_form_FORMID_alter().
*/
function islandora_collection_search_form_islandora_solr_advanced_search_form_alter(&$form, &$form_state) {
if (variable_get('islandora_collection_search_advanced_search_alter', FALSE)) {
module_load_include('inc', 'islandora_collection_search', 'includes/utilities');
$default_options = array(
'all' => t('All collections'),
);
$collections = islandora_collection_search_retrieve_searchable_collections($default_options, FALSE);
$form['collections'] = array(
'#type' => 'select',
'#options' => $collections,
'#weight' => 5,
);
$form['controls']['#weight'] = 6;
$form['#submit'][] = 'islandora_collection_search_append_collection_pid';
}
}
/**
* Submit handler which appends the collection PID to the query.
*
* @param array $form
* An array representing a form within Drupal.
* @param array $form_state
* An array representing the Drupal form state.
*/
function islandora_collection_search_append_collection_pid($form, &$form_state) {
if ($form_state['values']['collections'] != 'all') {
$form_state['redirect'][1]['query']['cp'] = $form_state['values']['collections'];
}
}