forked from symphonists/symphony_tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.driver.php
203 lines (174 loc) · 4.7 KB
/
extension.driver.php
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
/**
* @package symphony_tests
*/
/**
* A SimpleTest interface for Symphony.
*/
class Extension_Symphony_Tests extends Extension {
/**
* Is the devkit active?
* @var boolean
*/
protected $devkit_active = false;
/**
* True when no navigation group has been specified.
* @var boolean
*/
protected $missing_navigation_group = false;
/**
* Cleanup installation.
*/
public function uninstall() {
Symphony::Configuration()->remove('symphony_tests');
}
/**
* Create configuration.
*/
public function install() {
Symphony::Configuration()->set('navigation_group', __('System'), 'symphony_tests');
Administration::instance()->saveConfig();
return true;
}
/**
* Listen for these delegates.
*/
public function getSubscribedDelegates() {
return array(
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'viewPreferences'
),
array(
'page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => 'actionsPreferences'
),
array(
'page' => '/frontend/',
'delegate' => 'FrontendDevKitResolve',
'callback' => 'frontendDevKitResolve'
),
array(
'page' => '/frontend/',
'delegate' => 'ManipulateDevKitNavigation',
'callback' => 'manipulateDevKitNavigation'
)
);
}
/**
* Add navigation items.
*/
public function fetchNavigation() {
$group = $this->getNavigationGroup();
return array(
array(
'location' => $group,
'name' => __('Tests'),
'link' => '/tests/'
),
array(
'location' => $group,
'name' => __('Tests'),
'link' => '/test/',
'visible' => 'no'
)
);
}
/**
* Get the current extension directory.
*/
public function getExtensionDir() {
return dirname(__FILE__);
}
/**
* Show the devkit when someone accesses ?tests
*/
public function frontendDevKitResolve($context) {
if (isset($_GET['tests'])) {
require_once(EXTENSIONS . '/symphony_tests/content/content.devkit.php');
$context['devkit'] = new Content_TestsDevKit();
$this->devkit_active = true;
}
}
/**
* Add "Tests" to the devkit menu.
*/
public function manipulateDevKitNavigation($context) {
$xml = $context['xml'];
$item = $xml->createElement('item');
$item->setAttribute('name', __('Tests'));
$item->setAttribute('handle', 'tests');
$item->setAttribute('active', (
$this->devkit_active
? 'yes' : 'no'
));
$xml->documentElement->appendChild($item);
}
/**
* Get the name of the desired navigation group.
*/
public function getNavigationGroup() {
if ($this->missing_navigation_group === true) return null;
return Symphony::Configuration()->get('navigation_group', 'symphony_tests');
}
/**
* Get a list of available navigation groups.
*/
public function getNavigationGroups() {
$sections = SectionManager::fetch(null, 'ASC', 'sortorder');
$options = array();
if (is_array($sections)) foreach ($sections as $section) {
$options[] = $section->get('navigation_group');
}
$options[] = __('Blueprints');
$options[] = __('System');
return array_unique($options);
}
/**
* Validate preferences before saving.
* @param array $context
*/
public function actionsPreferences($context) {
if (
!isset($context['settings']['symphony_tests']['navigation_group'])
|| trim($context['settings']['symphony_tests']['navigation_group']) == ''
) {
$context['errors']['symphony_tests']['navigation_group'] = __('This is a required field.');
$this->missing_navigation_group = true;
}
}
/**
* View preferences.
* @param array $context
*/
public function viewPreferences($context) {
$wrapper = $context['wrapper'];
$errors = Symphony::Engine()->Page->_errors;
$fieldset = new XMLElement('fieldset');
$fieldset->setAttribute('class', 'settings');
$fieldset->appendChild(new XMLElement('legend', __('Symphony Tests')));
$label = Widget::Label(
__('Navigation Group')
. ' <i>'
. __('Created if does not exist')
. '</i>'
);
$label->appendChild(Widget::Input(
'settings[symphony_tests][navigation_group]',
$this->getNavigationGroup()
));
if (isset($errors['symphony_tests']['navigation_group'])) {
$label = Widget::wrapFormElementWithError($label, $errors['symphony_tests']['navigation_group']);
}
$fieldset->appendChild($label);
$list = new XMLElement('ul');
$list->setAttribute('class', 'tags singular');
foreach ($this->getNavigationGroups() as $group) {
$list->appendChild(new XMLElement('li', $group));
}
$fieldset->appendChild($list);
$wrapper->appendChild($fieldset);
}
}