1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Builds placeholder replacement tokens system-wide data.
|
6 |
|
|
*
|
7 |
|
|
* This file handles tokens for the global 'variable' token type.
|
8 |
|
|
*/
|
9 |
|
|
|
10 |
|
|
/**
|
11 |
|
|
* Implements hook_token_info().
|
12 |
|
|
*/
|
13 |
|
|
function variable_token_info() {
|
14 |
|
|
$types['variable'] = array(
|
15 |
|
|
'name' => t("Variables"),
|
16 |
|
|
'description' => t("Tokens for variable values."),
|
17 |
|
|
);
|
18 |
|
|
$variable = array();
|
19 |
|
|
foreach (variable_get_info() as $name => $info) {
|
20 |
|
|
if (!empty($info['token'])) {
|
21 |
|
|
$variable[$name] = array(
|
22 |
|
|
'name' => $info['title'],
|
23 |
|
|
'description' => !empty($info['description']) ? $info['description'] : t('Value of variable !name', array('!name' => $info['title'])),
|
24 |
|
|
);
|
25 |
|
|
}
|
26 |
|
|
}
|
27 |
|
|
return array(
|
28 |
|
|
'types' => $types,
|
29 |
|
|
'tokens' => array(
|
30 |
|
|
'variable' => $variable,
|
31 |
|
|
),
|
32 |
|
|
);
|
33 |
|
|
}
|
34 |
|
|
|
35 |
|
|
/**
|
36 |
|
|
* Implements hook_tokens().
|
37 |
|
|
*/
|
38 |
|
|
function variable_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
39 |
|
|
$replacements = array();
|
40 |
|
|
|
41 |
|
|
if ($type == 'variable') {
|
42 |
|
|
foreach ($tokens as $name => $original) {
|
43 |
|
|
$variable = variable_get_info($name, $options);
|
44 |
|
|
if ($variable && !empty($variable['token'])) {
|
45 |
|
|
$replacements[$original] = variable_format_value($variable, $options);
|
46 |
|
|
}
|
47 |
|
|
}
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
return $replacements;
|
51 |
|
|
} |