1
|
<?php
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
class stylizer_ui extends ctools_export_ui {
|
7
|
|
8
|
|
9
|
public function access($op, $item) {
|
10
|
$access = parent::access($op, $item);
|
11
|
if ($op == 'add' && $access && empty($this->base_types)) {
|
12
|
|
13
|
$access = FALSE;
|
14
|
}
|
15
|
return $access;
|
16
|
}
|
17
|
|
18
|
|
19
|
public function list_form(&$form, &$form_state) {
|
20
|
ctools_include('stylizer');
|
21
|
parent::list_form($form, $form_state);
|
22
|
|
23
|
$all = array('all' => t('- All -'));
|
24
|
|
25
|
if (empty($this->base_types)) {
|
26
|
|
27
|
drupal_set_message($this->plugin['strings']['message']['missing base type'], 'warning');
|
28
|
}
|
29
|
|
30
|
$types = $all;
|
31
|
foreach ($this->base_types as $module => $info) {
|
32
|
foreach ($info as $key => $base_type) {
|
33
|
$types[$module . '-' . $key] = $base_type['title'];
|
34
|
}
|
35
|
}
|
36
|
|
37
|
$form['top row']['type'] = array(
|
38
|
'#type' => 'select',
|
39
|
'#title' => t('Type'),
|
40
|
'#options' => $types,
|
41
|
'#default_value' => 'all',
|
42
|
'#weight' => -10,
|
43
|
'#attributes' => array('class' => array('ctools-auto-submit')),
|
44
|
);
|
45
|
|
46
|
$plugins = ctools_get_style_bases();
|
47
|
$form_state['style_plugins'] = $plugins;
|
48
|
|
49
|
$options = $all;
|
50
|
|
51
|
foreach ($plugins as $name => $plugin) {
|
52
|
$options[$name] = $plugin['title'];
|
53
|
}
|
54
|
|
55
|
$form['top row']['base'] = array(
|
56
|
'#type' => 'select',
|
57
|
'#title' => t('Base'),
|
58
|
'#options' => $all + $options,
|
59
|
'#default_value' => 'all',
|
60
|
'#weight' => -9,
|
61
|
'#attributes' => array('class' => array('ctools-auto-submit')),
|
62
|
);
|
63
|
}
|
64
|
|
65
|
|
66
|
public function list_sort_options() {
|
67
|
return array(
|
68
|
'disabled' => t('Enabled, title'),
|
69
|
'title' => t('Title'),
|
70
|
'name' => t('Name'),
|
71
|
'base' => t('Base'),
|
72
|
'type' => t('Type'),
|
73
|
'storage' => t('Storage'),
|
74
|
);
|
75
|
}
|
76
|
|
77
|
|
78
|
public function list_filter($form_state, $item) {
|
79
|
if (empty($form_state['style_plugins'][$item->settings['style_base']])) {
|
80
|
$this->style_plugin = array(
|
81
|
'name' => 'broken',
|
82
|
'title' => t('Missing plugin'),
|
83
|
'type' => t('Unknown'),
|
84
|
'module' => '',
|
85
|
);
|
86
|
}
|
87
|
else {
|
88
|
$this->style_plugin = $form_state['style_plugins'][$item->settings['style_base']];
|
89
|
}
|
90
|
|
91
|
|
92
|
|
93
|
$item->plugin_title = $this->style_plugin['title'];
|
94
|
|
95
|
if ($form_state['values']['type'] != 'all') {
|
96
|
list($module, $type) = explode('-', $form_state['values']['type']);
|
97
|
if ($module != $this->style_plugin['module'] || $type != $this->style_plugin['type']) {
|
98
|
return TRUE;
|
99
|
}
|
100
|
}
|
101
|
|
102
|
if ($form_state['values']['base'] != 'all' && $form_state['values']['base'] != $this->style_plugin['name']) {
|
103
|
return TRUE;
|
104
|
}
|
105
|
|
106
|
return parent::list_filter($form_state, $item);
|
107
|
}
|
108
|
|
109
|
|
110
|
public function list_search_fields() {
|
111
|
$fields = parent::list_search_fields();
|
112
|
$fields[] = 'plugin_title';
|
113
|
return $fields;
|
114
|
}
|
115
|
|
116
|
|
117
|
public function list_build_row($item, &$form_state, $operations) {
|
118
|
|
119
|
switch ($form_state['values']['order']) {
|
120
|
case 'disabled':
|
121
|
$this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
|
122
|
break;
|
123
|
|
124
|
case 'title':
|
125
|
$this->sorts[$item->name] = $item->admin_title;
|
126
|
break;
|
127
|
|
128
|
case 'name':
|
129
|
$this->sorts[$item->name] = $item->name;
|
130
|
break;
|
131
|
|
132
|
case 'type':
|
133
|
$this->sorts[$item->name] = $this->style_plugin['type'] . $item->admin_title;
|
134
|
break;
|
135
|
|
136
|
case 'base':
|
137
|
$this->sorts[$item->name] = $this->style_plugin['title'] . $item->admin_title;
|
138
|
break;
|
139
|
|
140
|
case 'storage':
|
141
|
$this->sorts[$item->name] = $item->type . $item->admin_title;
|
142
|
break;
|
143
|
}
|
144
|
|
145
|
if (!empty($this->base_types[$this->style_plugin['module']][$this->style_plugin['type']])) {
|
146
|
$type = $this->base_types[$this->style_plugin['module']][$this->style_plugin['type']]['title'];
|
147
|
}
|
148
|
else {
|
149
|
$type = t('Unknown');
|
150
|
}
|
151
|
|
152
|
$ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
|
153
|
|
154
|
$this->rows[$item->name] = array(
|
155
|
'data' => array(
|
156
|
array('data' => $type, 'class' => array('ctools-export-ui-type')),
|
157
|
array('data' => check_plain($item->name), 'class' => array('ctools-export-ui-name')),
|
158
|
array('data' => check_plain($item->admin_title), 'class' => array('ctools-export-ui-title')),
|
159
|
array('data' => check_plain($this->style_plugin['title']), 'class' => array('ctools-export-ui-base')),
|
160
|
array('data' => check_plain($item->type), 'class' => array('ctools-export-ui-storage')),
|
161
|
array('data' => $ops, 'class' => array('ctools-export-ui-operations')),
|
162
|
),
|
163
|
'title' => check_plain($item->admin_description),
|
164
|
'class' => array(!empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled'),
|
165
|
);
|
166
|
}
|
167
|
|
168
|
|
169
|
public function list_table_header() {
|
170
|
return array(
|
171
|
array('data' => t('Type'), 'class' => array('ctools-export-ui-type')),
|
172
|
array('data' => t('Name'), 'class' => array('ctools-export-ui-name')),
|
173
|
array('data' => t('Title'), 'class' => array('ctools-export-ui-title')),
|
174
|
array('data' => t('Base'), 'class' => array('ctools-export-ui-base')),
|
175
|
array('data' => t('Storage'), 'class' => array('ctools-export-ui-storage')),
|
176
|
array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations')),
|
177
|
);
|
178
|
}
|
179
|
|
180
|
|
181
|
public function init($plugin) {
|
182
|
ctools_include('stylizer');
|
183
|
$this->base_types = ctools_get_style_base_types();
|
184
|
|
185
|
parent::init($plugin);
|
186
|
}
|
187
|
|
188
|
|
189
|
public function get_wizard_info(&$form_state) {
|
190
|
$form_info = parent::get_wizard_info($form_state);
|
191
|
ctools_include('stylizer');
|
192
|
|
193
|
|
194
|
|
195
|
|
196
|
if (!empty($form_state['type'])) {
|
197
|
$form_state['form type'] = 'add';
|
198
|
$form_info['show back'] = TRUE;
|
199
|
}
|
200
|
|
201
|
|
202
|
$form_state['item']->settings['name'] = $form_state['item']->name;
|
203
|
$form_state['settings'] = $form_state['item']->settings;
|
204
|
|
205
|
|
206
|
$plugin = NULL;
|
207
|
if (!empty($form_state['item']->settings['style_base'])) {
|
208
|
$plugin = ctools_get_style_base($form_state['item']->settings['style_base']);
|
209
|
ctools_stylizer_add_plugin_forms($form_info, $plugin, $form_state['op']);
|
210
|
}
|
211
|
else {
|
212
|
|
213
|
|
214
|
|
215
|
$form_info['order']['next'] = t('Configure style');
|
216
|
|
217
|
}
|
218
|
|
219
|
|
220
|
if (!empty($form_state['item']->style_module)) {
|
221
|
$form_state['module'] = $form_state['item']->style_module;
|
222
|
$form_state['type'] = $form_state['item']->style_type;
|
223
|
}
|
224
|
|
225
|
$form_state['base_style_plugin'] = $plugin;
|
226
|
$form_state['settings'] = $form_state['item']->settings;
|
227
|
return $form_info;
|
228
|
}
|
229
|
|
230
|
|
231
|
|
232
|
|
233
|
|
234
|
|
235
|
|
236
|
public function store_stylizer_info(&$form_state) {
|
237
|
|
238
|
|
239
|
|
240
|
|
241
|
|
242
|
|
243
|
|
244
|
|
245
|
if ($form_state['step'] != 'import') {
|
246
|
$form_state['item']->settings = $form_state['settings'];
|
247
|
}
|
248
|
|
249
|
$form_state['item']->settings['name'] = $form_state['item']->name;
|
250
|
}
|
251
|
|
252
|
|
253
|
public function edit_wizard_next(&$form_state) {
|
254
|
$this->store_stylizer_info($form_state);
|
255
|
parent::edit_wizard_next($form_state);
|
256
|
}
|
257
|
|
258
|
|
259
|
public function edit_wizard_finish(&$form_state) {
|
260
|
|
261
|
if (isset($form_state['settings']['old_settings'])) {
|
262
|
unset($form_state['settings']['old_settings']);
|
263
|
}
|
264
|
$this->store_stylizer_info($form_state);
|
265
|
parent::edit_wizard_finish($form_state);
|
266
|
}
|
267
|
|
268
|
|
269
|
public function edit_form_type(&$form, &$form_state) {
|
270
|
foreach ($this->base_types as $module => $info) {
|
271
|
foreach ($info as $key => $base_type) {
|
272
|
$types[$module . '-' . $key] = $base_type['title'];
|
273
|
}
|
274
|
}
|
275
|
|
276
|
$form['type'] = array(
|
277
|
'#type' => 'select',
|
278
|
'#title' => t('Type'),
|
279
|
'#options' => $types,
|
280
|
'#default_value' => 'all',
|
281
|
'#weight' => -10,
|
282
|
'#attributes' => array('class' => array('ctools-auto-submit')),
|
283
|
);
|
284
|
}
|
285
|
|
286
|
|
287
|
public function edit_form_type_submit(&$form, &$form_state) {
|
288
|
list($form_state['item']->style_module, $form_state['item']->style_type) = explode('-', $form_state['values']['type']);
|
289
|
}
|
290
|
|
291
|
}
|