-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_settings.handlers.inc
146 lines (138 loc) · 4.33 KB
/
system_settings.handlers.inc
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
138
139
140
141
142
143
144
145
146
<?php
// $Id$
/**
* @file
* Provide a way to use swappable plugins for any part of the system as inspired by Crell
* (Larry Garfield)'s post here: http://www.garfieldtech.com/blog/drupal-handler-rfc
* and here: http://www.garfieldtech.com/blog/handlers-rfc-2
*
* If a pluggable handler's system lands in core (fingers crossed) this code will be deprecated.
*/
/**
* Returns a loaded system_settings handler appropriate to the targer.
*
* @param $target
* The name of the system_settings target.
* @return
* The appropriate system_settings handler object.
*/
function system_settings_get_target_handler($target) {
static $handlers = array();
if (!isset($handlers[$target])) {
$map = system_settings_handler_map();
$handlers[$target] = system_settings_target_handler_factory($map[$target]);
}
return $handlers[$target];
}
/**
* Load and configure a system_settings handler.
*
* @param $handler_data
* An array with keys 'handler', 'path', and 'class'
* of the handler, path to, and name of the class.
*/
function system_settings_target_handler_factory($handler_data) {
$path = drupal_get_path('module', 'system_settings') . '/handlers/system_settings.handler.interface.inc';
require_once($handler_data['path']);
$handler = 'SystemSettings' . $handler_data['class'] . 'Handler';
$handler = new $handler;
$conf = array();
if (isset($handler_data['conf'])) {
$conf = $handler_data['conf'];
}
$handler->configure($conf);
return $handler;
}
/**
* Retrieves an array of all system_settings
* handlers and the relevant data.
*
* @return (array)
* An array of all avaialable system_settings handlers.
*/
function system_settings_get_handlers() {
static $handlers;
if (is_null($handlers)) {
$handlers = module_invoke_all('system_settings_handlers');
}
return $handlers;
}
/**
* Retrieves an array of all system_settings
* targets.
*
* @return (array)
* An array of all avaialable system_settings targets.
*/
function system_settings_get_targets() {
static $targets;
if (is_null($targets)) {
$targets = module_invoke_all('system_settings_targets');
}
return $targets;
}
/**
* Implementation of hook_system_settings_handlers().
*/
function system_settings_system_settings_handlers() {
$path = drupal_get_path('module', 'system_settings') . '/handlers/';
$handlers = array(
'default' => array(
'path' => $path . 'system_settings.handler.default.inc',
'supported targets' => system_settings_system_settings_targets(),
'class' => 'Default',
// TODO: This should recursively autoload necessary parents.
// The farthest upstream parent should be the interface.
// (we'll need to figure out how to find the path for it)
'parent' => '',
),
'static_files' => array(
'path' => $path . 'system_settings.handler.static_files.inc',
'supported targets' => system_settings_system_settings_targets(),
'class' => 'Default',
'parent' => '',
),
);
return $handlers;
}
/**
* Implementation of hook_system_settings_targets().
*/
function system_settings_system_settings_targets() {
$targets = array(
'system_settings',
'system_settings_log',
);
return $targets;
}
/**
* Maps system_settings targets to system_settings handlers.
*
* @return
* An array keyed by target containing arrays with keys for 'handler' and 'path'.
*/
function system_settings_handler_map() {
static $handler_map;
if (is_null($handler_map)) {
$handlers = system_settings_get_handlers();
$handlers_settings = system_settings_pre_init_settings_get('system_settings_handlers');
$targets = system_settings_get_targets();
$handler_map = array();
foreach ($targets as $target) {
if (isset($handlers_settings[$target]['handler'])) {
$target_handler = $handlers_settings[$target]['handler'];
if (isset($handlers[$target_handler]) && in_array($target, $handlers[$target_handler]['supported targets'])) {
$handler_map[$target] = array(
'handler' => $target_handler,
'path' => $handlers[$target_handler]['path'],
'class' => $handlers[$target_handler]['class'],
);
if (isset($handlers_settings[$target]['conf'])) {
$handler_map[$target]['conf'] = $handlers_settings[$target]['conf'];
}
}
}
}
}
return $handler_map;
}