1
|
<?php
|
2
|
/**
|
3
|
* Variable example.
|
4
|
*/
|
5
|
|
6
|
/**
|
7
|
* Implements hook_variable_realm_info()
|
8
|
*/
|
9
|
function variable_example_variable_realm_info() {
|
10
|
$realm['example'] = array(
|
11
|
'title' => t('Example'),
|
12
|
'weight' => 10,
|
13
|
'store class' => 'VariableStoreRealmStore',
|
14
|
'keys' => array(
|
15
|
'first' => t('First example'),
|
16
|
'second' => t('Second example'),
|
17
|
),
|
18
|
);
|
19
|
return $realm;
|
20
|
}
|
21
|
|
22
|
/**
|
23
|
* Implements hook_menu().
|
24
|
*/
|
25
|
function variable_example_menu() {
|
26
|
$items['admin/config/system/variable_example'] = array(
|
27
|
'title' => 'Variable example',
|
28
|
'description' => 'Example of auto generated settings form.',
|
29
|
'page callback' => 'drupal_get_form',
|
30
|
'page arguments' => array('variable_group_form', 'variable_example'),
|
31
|
'access arguments' => array('administer site configuration'),
|
32
|
);
|
33
|
$items['variable/example'] = array(
|
34
|
'title' => 'Variable example',
|
35
|
'description' => 'List some variables.',
|
36
|
'page callback' => 'variable_example_page_list',
|
37
|
'access arguments' => array('administer site configuration'),
|
38
|
);
|
39
|
$items['variable/realm/%/%'] = array(
|
40
|
'title' => 'Variable example realm',
|
41
|
'description' => 'Example of variable realms.',
|
42
|
'page callback' => 'variable_example_page_realm',
|
43
|
'page arguments' => array(2, 3),
|
44
|
'access arguments' => array('administer site configuration'),
|
45
|
);
|
46
|
return $items;
|
47
|
}
|
48
|
|
49
|
/**
|
50
|
* Variable example realm page.
|
51
|
*
|
52
|
* Will switch to given realm and display variables.
|
53
|
*/
|
54
|
function variable_example_page_list() {
|
55
|
variable_include();
|
56
|
$list = variable_list_group('site_information') + variable_list_group('variable_example');
|
57
|
foreach ($list as $name => $variable) {
|
58
|
$build[$name] = array(
|
59
|
'#type' => 'item',
|
60
|
'#title' => $variable['title'],
|
61
|
'#markup' => variable_format_value($variable),
|
62
|
);
|
63
|
}
|
64
|
return $build;
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* Variable example realm page.
|
69
|
*
|
70
|
* Will switch to given realm and display variables.
|
71
|
*/
|
72
|
function variable_example_page_realm($realm, $key) {
|
73
|
// Initialize realm from variable store.
|
74
|
$variables = variable_store($realm, $key);
|
75
|
// Set at least one variable for the realm
|
76
|
$variables += array('site_name' => 'Variable example realm');
|
77
|
variable_realm_add($realm, $key, $variables);
|
78
|
variable_realm_switch($realm, $key);
|
79
|
return variable_example_page_list();
|
80
|
}
|
81
|
|