-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquery_registry.module
88 lines (79 loc) · 2.52 KB
/
query_registry.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
<?php
/**
* @file
* Primary hook implementations.
*/
// Hooks.
const QUERY_REGISTRY_REGISTER_IMPLEMENTATION = 'query_registry_register_implementations';
const QUERY_REGISTRY_REGISTER_QUERY = 'query_registry_register_queries';
const QUERY_REGISTRY_DEFAULT = 'module_default';
/**
* Implements hook_menu().
*/
function query_registry_menu() {
return array(
'admin/config/search/query_registry' => array(
'title' => 'Query Registry Configuration',
'description' => 'Select which queries to use.',
'page callback' => 'drupal_get_form',
'page arguments' => array('query_registry_admin_form'),
'file' => 'includes/admin.form.inc',
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
),
);
}
/**
* Run the query as outlined in the registry.
*
* @param string $query_identifier
* The query to route.
* @param array $query_args
* The parameters to pass to the query implementation.
*
* @return mixed
* NULL for use module default or the result of the query.
*/
function query_registry_run_query($query_identifier, $query_args = array()) {
$query_definition = query_registry_get_query($query_identifier);
// If module defaults are to be used return NULL.
if (is_null($query_definition)) {
return NULL;
}
// Include the necessary file.
if (isset($query_definition['extension']) && isset($query_definition['filename'])) {
$included = module_load_include(
$query_definition['extension'],
$query_definition['module'],
$query_definition['filename']
);
if (!$included) {
watchdog(
'query_registry',
'Could not include a query implementation. Please verify configuration.',
array(),
WATCHDOG_WARNING
);
return NULL;
}
}
return call_user_func_array($query_definition['callable'], $query_args);
}
/**
* Get the query as outlined in the registry.
*
* @param string $query_identifier
* The query to route.
*
* @return mixed
* NULL for use module default or the query array.
*/
function query_registry_get_query($query_identifier) {
$query_registers = variable_get('query_registry_selected_queries', array());
// If module defaults are to be used return NULL.
if (!isset($query_registers[$query_identifier]) || $query_registers[$query_identifier] == QUERY_REGISTRY_DEFAULT) {
return NULL;
}
$query_definitions = module_invoke($query_registers[$query_identifier], QUERY_REGISTRY_REGISTER_IMPLEMENTATION);
return $query_definitions[$query_identifier];
}