1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
class ctools_export_ui {
|
7 |
|
|
var $plugin;
|
8 |
|
|
var $name;
|
9 |
|
|
var $options = array();
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
function init($plugin) {
|
17 |
|
|
ctools_include('export');
|
18 |
|
|
|
19 |
|
|
$this->plugin = $plugin;
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
function get_page_title($op, $item = NULL) {
|
26 |
|
|
if (empty($this->plugin['strings']['title'][$op])) {
|
27 |
|
|
return;
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
$title = $this->plugin['strings']['title'][$op];
|
32 |
|
|
if (!empty($item)) {
|
33 |
|
|
$export_key = $this->plugin['export']['key'];
|
34 |
|
|
$title = (str_replace('%title', check_plain($item->{$export_key}), $title));
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
return $title;
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
function load_item($item_name) {
|
47 |
|
|
$item = ctools_export_crud_load($this->plugin['schema'], $item_name);
|
48 |
|
|
return empty($item) ? FALSE : $item;
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
function hook_menu(&$items) {
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
if (empty($this->plugin['schema'])) {
|
65 |
|
|
return;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
$prefix = ctools_export_ui_plugin_base_path($this->plugin);
|
69 |
|
|
|
70 |
|
|
if (isset($this->plugin['menu']['items']) && is_array($this->plugin['menu']['items'])) {
|
71 |
|
|
$my_items = array();
|
72 |
|
|
foreach ($this->plugin['menu']['items'] as $item) {
|
73 |
|
|
|
74 |
|
|
$item += array(
|
75 |
|
|
'file' => 'export-ui.inc',
|
76 |
|
|
'file path' => drupal_get_path('module', 'ctools') . '/includes',
|
77 |
|
|
);
|
78 |
|
|
|
79 |
|
|
$path = !empty($item['path']) ? $prefix . '/' . $item['path'] : $prefix;
|
80 |
|
|
unset($item['path']);
|
81 |
|
|
$my_items[$path] = $item;
|
82 |
|
|
}
|
83 |
|
|
$items += $my_items;
|
84 |
|
|
}
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
function access($op, $item) {
|
103 |
|
|
if (!user_access($this->plugin['access'])) {
|
104 |
|
|
return FALSE;
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
if ($op == 'add' && !user_access($this->plugin['create access'])) {
|
109 |
|
|
return FALSE;
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
if (($op == 'revert' || $op == 'delete') && !user_access($this->plugin['delete access'])) {
|
114 |
|
|
return FALSE;
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
if (!empty($this->plugin['allowed operations'][$op]['token']) && (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], $op))) {
|
119 |
|
|
return FALSE;
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
switch ($op) {
|
123 |
|
|
case 'import':
|
124 |
e4c061ad
|
Assos Assos
|
return user_access('use ctools import');
|
125 |
85ad3d82
|
Assos Assos
|
case 'revert':
|
126 |
|
|
return ($item->export_type & EXPORT_IN_DATABASE) && ($item->export_type & EXPORT_IN_CODE);
|
127 |
|
|
case 'delete':
|
128 |
|
|
return ($item->export_type & EXPORT_IN_DATABASE) && !($item->export_type & EXPORT_IN_CODE);
|
129 |
|
|
case 'disable':
|
130 |
|
|
return empty($item->disabled);
|
131 |
|
|
case 'enable':
|
132 |
|
|
return !empty($item->disabled);
|
133 |
|
|
default:
|
134 |
|
|
return TRUE;
|
135 |
|
|
}
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
function list_page($js, $input) {
|
148 |
|
|
$this->items = ctools_export_crud_load_all($this->plugin['schema'], $js);
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
if (isset($input['op']) && $input['op'] == t('Reset')) {
|
153 |
|
|
unset($_SESSION['ctools_export_ui'][$this->plugin['name']]);
|
154 |
|
|
if (!$js) {
|
155 |
3753f249
|
Assos Assos
|
drupal_goto($_GET['q']);
|
156 |
85ad3d82
|
Assos Assos
|
}
|
157 |
|
|
|
158 |
|
|
$keys = array_keys($input);
|
159 |
|
|
foreach ($keys as $id) {
|
160 |
|
|
if (!in_array($id, array('form_id', 'form_build_id', 'form_token'))) {
|
161 |
|
|
unset($input[$id]);
|
162 |
|
|
}
|
163 |
|
|
}
|
164 |
|
|
$replace_form = TRUE;
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
if (!isset($input['form_id'])) {
|
170 |
|
|
if (isset($_SESSION['ctools_export_ui'][$this->plugin['name']]) && is_array($_SESSION['ctools_export_ui'][$this->plugin['name']])) {
|
171 |
|
|
$input = $_SESSION['ctools_export_ui'][$this->plugin['name']];
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
|
|
else {
|
175 |
|
|
$_SESSION['ctools_export_ui'][$this->plugin['name']] = $input;
|
176 |
|
|
unset($_SESSION['ctools_export_ui'][$this->plugin['name']]['q']);
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
$this->rows = array();
|
181 |
|
|
$this->sorts = array();
|
182 |
|
|
|
183 |
|
|
$form_state = array(
|
184 |
|
|
'plugin' => $this->plugin,
|
185 |
|
|
'input' => $input,
|
186 |
|
|
'rerender' => TRUE,
|
187 |
|
|
'no_redirect' => TRUE,
|
188 |
|
|
'object' => &$this,
|
189 |
|
|
);
|
190 |
|
|
if (!isset($form_state['input']['form_id'])) {
|
191 |
|
|
$form_state['input']['form_id'] = 'ctools_export_ui_list_form';
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
if ($js && isset($_POST['ajax_html_ids'])) {
|
197 |
|
|
unset($_POST['ajax_html_ids']);
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
$form = drupal_build_form('ctools_export_ui_list_form', $form_state);
|
201 |
|
|
$form = drupal_render($form);
|
202 |
|
|
|
203 |
|
|
$output = $this->list_header($form_state) . $this->list_render($form_state) . $this->list_footer($form_state);
|
204 |
|
|
|
205 |
|
|
if (!$js) {
|
206 |
|
|
$this->list_css();
|
207 |
|
|
return $form . $output;
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
$commands = array();
|
211 |
|
|
$commands[] = ajax_command_replace('#ctools-export-ui-list-items', $output);
|
212 |
|
|
if (!empty($replace_form)) {
|
213 |
|
|
$commands[] = ajax_command_replace('#ctools-export-ui-list-form', $form);
|
214 |
|
|
}
|
215 |
|
|
print ajax_render($commands);
|
216 |
|
|
ajax_footer();
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
function list_form(&$form, &$form_state) {
|
228 |
|
|
|
229 |
|
|
|
230 |
|
|
$form['#token'] = FALSE;
|
231 |
|
|
if (empty($form_state['input'])) {
|
232 |
|
|
$form["#post"] = TRUE;
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
|
236 |
|
|
|
237 |
|
|
if (!variable_get('clean_url', FALSE)) {
|
238 |
|
|
$form['q'] = array(
|
239 |
|
|
'#type' => 'hidden',
|
240 |
|
|
'#value' => $_GET['q'],
|
241 |
|
|
);
|
242 |
|
|
}
|
243 |
|
|
|
244 |
|
|
$all = array('all' => t('- All -'));
|
245 |
|
|
|
246 |
|
|
$form['top row'] = array(
|
247 |
|
|
'#prefix' => '<div class="ctools-export-ui-row ctools-export-ui-top-row clearfix">',
|
248 |
|
|
'#suffix' => '</div>',
|
249 |
|
|
);
|
250 |
|
|
|
251 |
|
|
$form['bottom row'] = array(
|
252 |
|
|
'#prefix' => '<div class="ctools-export-ui-row ctools-export-ui-bottom-row clearfix">',
|
253 |
|
|
'#suffix' => '</div>',
|
254 |
|
|
);
|
255 |
|
|
|
256 |
|
|
$form['top row']['storage'] = array(
|
257 |
|
|
'#type' => 'select',
|
258 |
|
|
'#title' => t('Storage'),
|
259 |
|
|
'#options' => $all + array(
|
260 |
|
|
t('Normal') => t('Normal'),
|
261 |
|
|
t('Default') => t('Default'),
|
262 |
|
|
t('Overridden') => t('Overridden'),
|
263 |
|
|
),
|
264 |
|
|
'#default_value' => 'all',
|
265 |
|
|
);
|
266 |
|
|
|
267 |
|
|
$form['top row']['disabled'] = array(
|
268 |
|
|
'#type' => 'select',
|
269 |
|
|
'#title' => t('Enabled'),
|
270 |
|
|
'#options' => $all + array(
|
271 |
|
|
'0' => t('Enabled'),
|
272 |
|
|
'1' => t('Disabled')
|
273 |
|
|
),
|
274 |
|
|
'#default_value' => 'all',
|
275 |
|
|
);
|
276 |
|
|
|
277 |
|
|
$form['top row']['search'] = array(
|
278 |
|
|
'#type' => 'textfield',
|
279 |
|
|
'#title' => t('Search'),
|
280 |
|
|
);
|
281 |
|
|
|
282 |
|
|
$form['bottom row']['order'] = array(
|
283 |
|
|
'#type' => 'select',
|
284 |
|
|
'#title' => t('Sort by'),
|
285 |
|
|
'#options' => $this->list_sort_options(),
|
286 |
|
|
'#default_value' => 'disabled',
|
287 |
|
|
);
|
288 |
|
|
|
289 |
|
|
$form['bottom row']['sort'] = array(
|
290 |
|
|
'#type' => 'select',
|
291 |
|
|
'#title' => t('Order'),
|
292 |
|
|
'#options' => array(
|
293 |
|
|
'asc' => t('Up'),
|
294 |
|
|
'desc' => t('Down'),
|
295 |
|
|
),
|
296 |
|
|
'#default_value' => 'asc',
|
297 |
|
|
);
|
298 |
|
|
|
299 |
|
|
$form['bottom row']['submit'] = array(
|
300 |
|
|
'#type' => 'submit',
|
301 |
|
|
'#id' => 'ctools-export-ui-list-items-apply',
|
302 |
|
|
'#value' => t('Apply'),
|
303 |
|
|
'#attributes' => array('class' => array('use-ajax-submit ctools-auto-submit-click')),
|
304 |
|
|
);
|
305 |
|
|
|
306 |
|
|
$form['bottom row']['reset'] = array(
|
307 |
|
|
'#type' => 'submit',
|
308 |
|
|
'#id' => 'ctools-export-ui-list-items-apply',
|
309 |
|
|
'#value' => t('Reset'),
|
310 |
|
|
'#attributes' => array('class' => array('use-ajax-submit')),
|
311 |
|
|
);
|
312 |
|
|
|
313 |
|
|
$form['#prefix'] = '<div class="clearfix">';
|
314 |
|
|
$form['#suffix'] = '</div>';
|
315 |
|
|
$form['#attached']['js'] = array(ctools_attach_js('auto-submit'));
|
316 |
|
|
$form['#attached']['library'][] = array('system', 'drupal.ajax');
|
317 |
|
|
$form['#attached']['library'][] = array('system', 'jquery.form');
|
318 |
|
|
$form['#attributes'] = array('class' => array('ctools-auto-submit-full-form'));
|
319 |
|
|
}
|
320 |
|
|
|
321 |
|
|
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
|
|
|
327 |
|
|
function list_form_validate(&$form, &$form_state) { }
|
328 |
|
|
|
329 |
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
|
|
|
335 |
|
|
|
336 |
|
|
|
337 |
|
|
|
338 |
|
|
|
339 |
|
|
function list_form_submit(&$form, &$form_state) {
|
340 |
|
|
|
341 |
|
|
$plugin = $this->plugin;
|
342 |
|
|
|
343 |
|
|
$prefix = ctools_export_ui_plugin_base_path($plugin);
|
344 |
|
|
|
345 |
|
|
foreach ($this->items as $name => $item) {
|
346 |
|
|
|
347 |
|
|
|
348 |
|
|
if ($this->list_filter($form_state, $item)) {
|
349 |
|
|
continue;
|
350 |
|
|
}
|
351 |
|
|
|
352 |
|
|
$operations = $this->build_operations($item);
|
353 |
|
|
|
354 |
|
|
$this->list_build_row($item, $form_state, $operations);
|
355 |
|
|
}
|
356 |
|
|
|
357 |
|
|
|
358 |
|
|
if ($form_state['values']['sort'] == 'desc') {
|
359 |
|
|
arsort($this->sorts);
|
360 |
|
|
}
|
361 |
|
|
else {
|
362 |
|
|
asort($this->sorts);
|
363 |
|
|
}
|
364 |
|
|
|
365 |
|
|
|
366 |
|
|
$rows = $this->rows;
|
367 |
|
|
$this->rows = array();
|
368 |
|
|
|
369 |
|
|
foreach ($this->sorts as $name => $title) {
|
370 |
|
|
$this->rows[$name] = $rows[$name];
|
371 |
|
|
}
|
372 |
|
|
}
|
373 |
|
|
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
|
377 |
|
|
|
378 |
|
|
|
379 |
|
|
|
380 |
|
|
|
381 |
|
|
|
382 |
|
|
|
383 |
|
|
|
384 |
|
|
function list_filter($form_state, $item) {
|
385 |
|
|
$schema = ctools_export_get_schema($this->plugin['schema']);
|
386 |
|
|
if ($form_state['values']['storage'] != 'all' && $form_state['values']['storage'] != $item->{$schema['export']['export type string']}) {
|
387 |
|
|
return TRUE;
|
388 |
|
|
}
|
389 |
|
|
|
390 |
|
|
if ($form_state['values']['disabled'] != 'all' && $form_state['values']['disabled'] != !empty($item->disabled)) {
|
391 |
|
|
return TRUE;
|
392 |
|
|
}
|
393 |
|
|
|
394 |
|
|
if ($form_state['values']['search']) {
|
395 |
|
|
$search = strtolower($form_state['values']['search']);
|
396 |
|
|
foreach ($this->list_search_fields() as $field) {
|
397 |
|
|
if (strpos(strtolower($item->$field), $search) !== FALSE) {
|
398 |
|
|
$hit = TRUE;
|
399 |
|
|
break;
|
400 |
|
|
}
|
401 |
|
|
}
|
402 |
|
|
if (empty($hit)) {
|
403 |
|
|
return TRUE;
|
404 |
|
|
}
|
405 |
|
|
}
|
406 |
|
|
}
|
407 |
|
|
|
408 |
|
|
|
409 |
|
|
|
410 |
|
|
|
411 |
|
|
|
412 |
|
|
|
413 |
|
|
|
414 |
|
|
function list_search_fields() {
|
415 |
|
|
$fields = array(
|
416 |
|
|
$this->plugin['export']['key'],
|
417 |
|
|
);
|
418 |
|
|
|
419 |
|
|
if (!empty($this->plugin['export']['admin_title'])) {
|
420 |
|
|
$fields[] = $this->plugin['export']['admin_title'];
|
421 |
|
|
}
|
422 |
|
|
if (!empty($this->plugin['export']['admin_description'])) {
|
423 |
|
|
$fields[] = $this->plugin['export']['admin_description'];
|
424 |
|
|
}
|
425 |
|
|
|
426 |
|
|
return $fields;
|
427 |
|
|
}
|
428 |
|
|
|
429 |
|
|
|
430 |
|
|
|
431 |
|
|
|
432 |
|
|
|
433 |
|
|
|
434 |
|
|
|
435 |
|
|
function list_sort_options() {
|
436 |
|
|
if (!empty($this->plugin['export']['admin_title'])) {
|
437 |
|
|
$options = array(
|
438 |
|
|
'disabled' => t('Enabled, title'),
|
439 |
|
|
$this->plugin['export']['admin_title'] => t('Title'),
|
440 |
|
|
);
|
441 |
|
|
}
|
442 |
|
|
else {
|
443 |
|
|
$options = array(
|
444 |
|
|
'disabled' => t('Enabled, name'),
|
445 |
|
|
);
|
446 |
|
|
}
|
447 |
|
|
|
448 |
|
|
$options += array(
|
449 |
|
|
'name' => t('Name'),
|
450 |
|
|
'storage' => t('Storage'),
|
451 |
|
|
);
|
452 |
|
|
|
453 |
|
|
return $options;
|
454 |
|
|
}
|
455 |
|
|
|
456 |
|
|
|
457 |
|
|
|
458 |
|
|
|
459 |
|
|
|
460 |
|
|
|
461 |
|
|
function list_css() {
|
462 |
|
|
ctools_add_css('export-ui-list');
|
463 |
|
|
}
|
464 |
|
|
|
465 |
|
|
|
466 |
|
|
|
467 |
|
|
|
468 |
|
|
function build_operations($item) {
|
469 |
|
|
$plugin = $this->plugin;
|
470 |
|
|
$schema = ctools_export_get_schema($plugin['schema']);
|
471 |
|
|
$operations = $plugin['allowed operations'];
|
472 |
|
|
$operations['import'] = FALSE;
|
473 |
|
|
|
474 |
|
|
if ($item->{$schema['export']['export type string']} == t('Normal')) {
|
475 |
|
|
$operations['revert'] = FALSE;
|
476 |
|
|
}
|
477 |
|
|
elseif ($item->{$schema['export']['export type string']} == t('Overridden')) {
|
478 |
|
|
$operations['delete'] = FALSE;
|
479 |
|
|
}
|
480 |
|
|
else {
|
481 |
|
|
$operations['revert'] = FALSE;
|
482 |
|
|
$operations['delete'] = FALSE;
|
483 |
|
|
}
|
484 |
|
|
if (empty($item->disabled)) {
|
485 |
|
|
$operations['enable'] = FALSE;
|
486 |
|
|
}
|
487 |
|
|
else {
|
488 |
|
|
$operations['disable'] = FALSE;
|
489 |
|
|
}
|
490 |
|
|
|
491 |
|
|
$allowed_operations = array();
|
492 |
|
|
|
493 |
|
|
foreach ($operations as $op => $info) {
|
494 |
|
|
if (!empty($info)) {
|
495 |
|
|
$allowed_operations[$op] = array(
|
496 |
|
|
'title' => $info['title'],
|
497 |
|
|
'href' => ctools_export_ui_plugin_menu_path($plugin, $op, $item->{$this->plugin['export']['key']}),
|
498 |
|
|
);
|
499 |
|
|
if (!empty($info['ajax'])) {
|
500 |
|
|
$allowed_operations[$op]['attributes'] = array('class' => array('use-ajax'));
|
501 |
|
|
}
|
502 |
|
|
if (!empty($info['token'])) {
|
503 |
|
|
$allowed_operations[$op]['query'] = array('token' => drupal_get_token($op));
|
504 |
|
|
}
|
505 |
|
|
}
|
506 |
|
|
}
|
507 |
|
|
|
508 |
|
|
return $allowed_operations;
|
509 |
|
|
}
|
510 |
|
|
|
511 |
|
|
|
512 |
|
|
|
513 |
|
|
|
514 |
|
|
|
515 |
|
|
|
516 |
|
|
|
517 |
|
|
|
518 |
|
|
function list_build_row($item, &$form_state, $operations) {
|
519 |
|
|
|
520 |
|
|
$name = $item->{$this->plugin['export']['key']};
|
521 |
|
|
$schema = ctools_export_get_schema($this->plugin['schema']);
|
522 |
|
|
|
523 |
|
|
|
524 |
|
|
|
525 |
|
|
switch ($form_state['values']['order']) {
|
526 |
|
|
case 'disabled':
|
527 |
|
|
$this->sorts[$name] = empty($item->disabled) . $name;
|
528 |
|
|
break;
|
529 |
|
|
case 'title':
|
530 |
|
|
$this->sorts[$name] = $item->{$this->plugin['export']['admin_title']};
|
531 |
|
|
break;
|
532 |
|
|
case 'name':
|
533 |
|
|
$this->sorts[$name] = $name;
|
534 |
|
|
break;
|
535 |
|
|
case 'storage':
|
536 |
|
|
$this->sorts[$name] = $item->{$schema['export']['export type string']} . $name;
|
537 |
|
|
break;
|
538 |
|
|
}
|
539 |
|
|
|
540 |
|
|
$this->rows[$name]['data'] = array();
|
541 |
|
|
$this->rows[$name]['class'] = !empty($item->disabled) ? array('ctools-export-ui-disabled') : array('ctools-export-ui-enabled');
|
542 |
|
|
|
543 |
|
|
|
544 |
|
|
if (!empty($this->plugin['export']['admin_title'])) {
|
545 |
|
|
$this->rows[$name]['data'][] = array('data' => check_plain($item->{$this->plugin['export']['admin_title']}), 'class' => array('ctools-export-ui-title'));
|
546 |
|
|
}
|
547 |
|
|
$this->rows[$name]['data'][] = array('data' => check_plain($name), 'class' => array('ctools-export-ui-name'));
|
548 |
|
|
$this->rows[$name]['data'][] = array('data' => check_plain($item->{$schema['export']['export type string']}), 'class' => array('ctools-export-ui-storage'));
|
549 |
|
|
|
550 |
|
|
$ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
|
551 |
|
|
|
552 |
|
|
$this->rows[$name]['data'][] = array('data' => $ops, 'class' => array('ctools-export-ui-operations'));
|
553 |
|
|
|
554 |
|
|
|
555 |
|
|
if (!empty($this->plugin['export']['admin_description'])) {
|
556 |
|
|
$this->rows[$name]['title'] = $item->{$this->plugin['export']['admin_description']};
|
557 |
|
|
}
|
558 |
|
|
}
|
559 |
|
|
|
560 |
|
|
|
561 |
|
|
|
562 |
|
|
|
563 |
|
|
|
564 |
|
|
|
565 |
|
|
|
566 |
|
|
function list_table_header() {
|
567 |
|
|
$header = array();
|
568 |
|
|
if (!empty($this->plugin['export']['admin_title'])) {
|
569 |
|
|
$header[] = array('data' => t('Title'), 'class' => array('ctools-export-ui-title'));
|
570 |
|
|
}
|
571 |
|
|
|
572 |
|
|
$header[] = array('data' => t('Name'), 'class' => array('ctools-export-ui-name'));
|
573 |
|
|
$header[] = array('data' => t('Storage'), 'class' => array('ctools-export-ui-storage'));
|
574 |
|
|
$header[] = array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations'));
|
575 |
|
|
|
576 |
|
|
return $header;
|
577 |
|
|
}
|
578 |
|
|
|
579 |
|
|
|
580 |
|
|
|
581 |
|
|
|
582 |
|
|
|
583 |
|
|
|
584 |
|
|
|
585 |
|
|
|
586 |
|
|
|
587 |
|
|
|
588 |
|
|
function list_render(&$form_state) {
|
589 |
|
|
$table = array(
|
590 |
|
|
'header' => $this->list_table_header(),
|
591 |
|
|
'rows' => $this->rows,
|
592 |
|
|
'attributes' => array('id' => 'ctools-export-ui-list-items'),
|
593 |
|
|
'empty' => $this->plugin['strings']['message']['no items'],
|
594 |
|
|
);
|
595 |
|
|
return theme('table', $table);
|
596 |
|
|
}
|
597 |
|
|
|
598 |
|
|
|
599 |
|
|
|
600 |
|
|
|
601 |
|
|
|
602 |
|
|
|
603 |
|
|
function list_header($form_state) { }
|
604 |
|
|
|
605 |
|
|
|
606 |
|
|
|
607 |
|
|
|
608 |
|
|
|
609 |
|
|
|
610 |
|
|
function list_footer($form_state) { }
|
611 |
|
|
|
612 |
|
|
|
613 |
|
|
|
614 |
|
|
|
615 |
|
|
|
616 |
|
|
|
617 |
|
|
|
618 |
|
|
|
619 |
|
|
|
620 |
|
|
|
621 |
|
|
|
622 |
|
|
|
623 |
|
|
|
624 |
|
|
|
625 |
|
|
|
626 |
|
|
function redirect($op, $item = NULL) {
|
627 |
|
|
if (isset($this->plugin['redirect'][$op])) {
|
628 |
|
|
$destination = (array) $this->plugin['redirect'][$op];
|
629 |
|
|
if ($item) {
|
630 |
|
|
$export_key = $this->plugin['export']['key'];
|
631 |
|
|
$destination[0] = str_replace('%ctools_export_ui', $item->{$export_key}, $destination[0]);
|
632 |
|
|
}
|
633 |
|
|
call_user_func_array('drupal_goto', $destination);
|
634 |
|
|
}
|
635 |
|
|
else {
|
636 |
|
|
|
637 |
|
|
drupal_goto(ctools_export_ui_plugin_base_path($this->plugin));
|
638 |
|
|
}
|
639 |
|
|
}
|
640 |
|
|
|
641 |
|
|
function add_page($js, $input, $step = NULL) {
|
642 |
e4c061ad
|
Assos Assos
|
drupal_set_title($this->get_page_title('add'), PASS_THROUGH);
|
643 |
85ad3d82
|
Assos Assos
|
|
644 |
|
|
|
645 |
|
|
|
646 |
|
|
if (!empty($this->plugin['use wizard']) && !empty($step)) {
|
647 |
|
|
$item = $this->edit_cache_get(NULL, 'add');
|
648 |
|
|
}
|
649 |
|
|
if (empty($item)) {
|
650 |
|
|
$item = ctools_export_crud_new($this->plugin['schema']);
|
651 |
|
|
}
|
652 |
|
|
|
653 |
|
|
$form_state = array(
|
654 |
|
|
'plugin' => $this->plugin,
|
655 |
|
|
'object' => &$this,
|
656 |
|
|
'ajax' => $js,
|
657 |
|
|
'item' => $item,
|
658 |
|
|
'op' => 'add',
|
659 |
|
|
'form type' => 'add',
|
660 |
|
|
'rerender' => TRUE,
|
661 |
|
|
'no_redirect' => TRUE,
|
662 |
|
|
'step' => $step,
|
663 |
|
|
|
664 |
|
|
'function args' => func_get_args(),
|
665 |
|
|
);
|
666 |
|
|
|
667 |
|
|
$output = $this->edit_execute_form($form_state);
|
668 |
3753f249
|
Assos Assos
|
if (!empty($form_state['executed']) && empty($form_state['rebuild'])) {
|
669 |
85ad3d82
|
Assos Assos
|
$this->redirect($form_state['op'], $form_state['item']);
|
670 |
|
|
}
|
671 |
|
|
|
672 |
|
|
return $output;
|
673 |
|
|
}
|
674 |
|
|
|
675 |
|
|
|
676 |
|
|
|
677 |
|
|
|
678 |
|
|
function edit_page($js, $input, $item, $step = NULL) {
|
679 |
e4c061ad
|
Assos Assos
|
drupal_set_title($this->get_page_title('edit', $item), PASS_THROUGH);
|
680 |
85ad3d82
|
Assos Assos
|
|
681 |
|
|
|
682 |
|
|
if (!empty($this->plugin['use wizard'])) {
|
683 |
|
|
$cached = $this->edit_cache_get($item, 'edit');
|
684 |
|
|
if (!empty($cached)) {
|
685 |
|
|
$item = $cached;
|
686 |
|
|
}
|
687 |
|
|
}
|
688 |
|
|
|
689 |
|
|
$form_state = array(
|
690 |
|
|
'plugin' => $this->plugin,
|
691 |
|
|
'object' => &$this,
|
692 |
|
|
'ajax' => $js,
|
693 |
|
|
'item' => $item,
|
694 |
|
|
'op' => 'edit',
|
695 |
|
|
'form type' => 'edit',
|
696 |
|
|
'rerender' => TRUE,
|
697 |
|
|
'no_redirect' => TRUE,
|
698 |
|
|
'step' => $step,
|
699 |
|
|
|
700 |
|
|
'function args' => func_get_args(),
|
701 |
|
|
);
|
702 |
|
|
|
703 |
|
|
$output = $this->edit_execute_form($form_state);
|
704 |
3753f249
|
Assos Assos
|
if (!empty($form_state['executed']) && empty($form_state['rebuild'])) {
|
705 |
85ad3d82
|
Assos Assos
|
$this->redirect($form_state['op'], $form_state['item']);
|
706 |
|
|
}
|
707 |
|
|
|
708 |
|
|
return $output;
|
709 |
|
|
}
|
710 |
|
|
|
711 |
|
|
|
712 |
|
|
|
713 |
|
|
|
714 |
|
|
function clone_page($js, $input, $original, $step = NULL) {
|
715 |
e4c061ad
|
Assos Assos
|
drupal_set_title($this->get_page_title('clone', $original), PASS_THROUGH);
|
716 |
85ad3d82
|
Assos Assos
|
|
717 |
|
|
|
718 |
|
|
|
719 |
|
|
if (!empty($this->plugin['use wizard']) && !empty($step)) {
|
720 |
|
|
$item = $this->edit_cache_get(NULL, 'clone');
|
721 |
|
|
}
|
722 |
|
|
if (empty($item)) {
|
723 |
|
|
|
724 |
|
|
|
725 |
|
|
$export = ctools_export_crud_export($this->plugin['schema'], $original);
|
726 |
|
|
$item = ctools_export_crud_import($this->plugin['schema'], $export);
|
727 |
|
|
$item->{$this->plugin['export']['key']} = 'clone_of_' . $item->{$this->plugin['export']['key']};
|
728 |
|
|
}
|
729 |
|
|
|
730 |
|
|
|
731 |
|
|
|
732 |
|
|
$trail = menu_set_active_item(ctools_export_ui_plugin_base_path($this->plugin));
|
733 |
|
|
|
734 |
|
|
$name = $original->{$this->plugin['export']['key']};
|
735 |
|
|
|
736 |
|
|
$form_state = array(
|
737 |
|
|
'plugin' => $this->plugin,
|
738 |
|
|
'object' => &$this,
|
739 |
|
|
'ajax' => $js,
|
740 |
|
|
'item' => $item,
|
741 |
|
|
'op' => 'add',
|
742 |
|
|
'form type' => 'clone',
|
743 |
|
|
'original name' => $name,
|
744 |
|
|
'rerender' => TRUE,
|
745 |
|
|
'no_redirect' => TRUE,
|
746 |
|
|
'step' => $step,
|
747 |
|
|
|
748 |
|
|
'function args' => func_get_args(),
|
749 |
|
|
);
|
750 |
|
|
|
751 |
|
|
$output = $this->edit_execute_form($form_state);
|
752 |
3753f249
|
Assos Assos
|
if (!empty($form_state['executed']) && empty($form_state['rebuild'])) {
|
753 |
85ad3d82
|
Assos Assos
|
$this->redirect($form_state['op'], $form_state['item']);
|
754 |
|
|
}
|
755 |
|
|
|
756 |
|
|
return $output;
|
757 |
|
|
}
|
758 |
|
|
|
759 |
|
|
|
760 |
|
|
|
761 |
|
|
|
762 |
|
|
|
763 |
|
|
|
764 |
|
|
|
765 |
|
|
function edit_execute_form(&$form_state) {
|
766 |
|
|
if (!empty($this->plugin['use wizard'])) {
|
767 |
|
|
return $this->edit_execute_form_wizard($form_state);
|
768 |
|
|
}
|
769 |
|
|
else {
|
770 |
|
|
return $this->edit_execute_form_standard($form_state);
|
771 |
|
|
}
|
772 |
|
|
}
|
773 |
|
|
|
774 |
|
|
|
775 |
|
|
|
776 |
|
|
|
777 |
|
|
|
778 |
|
|
|
779 |
|
|
function edit_execute_form_standard(&$form_state) {
|
780 |
|
|
$output = drupal_build_form('ctools_export_ui_edit_item_form', $form_state);
|
781 |
3753f249
|
Assos Assos
|
if (!empty($form_state['executed']) && empty($form_state['rebuild'])) {
|
782 |
85ad3d82
|
Assos Assos
|
$this->edit_save_form($form_state);
|
783 |
|
|
}
|
784 |
|
|
|
785 |
|
|
return $output;
|
786 |
|
|
}
|
787 |
|
|
|
788 |
|
|
|
789 |
|
|
|
790 |
|
|
|
791 |
|
|
|
792 |
|
|
|
793 |
|
|
|
794 |
|
|
|
795 |
|
|
|
796 |
|
|
|
797 |
|
|
|
798 |
|
|
|
799 |
|
|
|
800 |
|
|
function get_wizard_info(&$form_state) {
|
801 |
|
|
if (!isset($form_state['step'])) {
|
802 |
|
|
$form_state['step'] = NULL;
|
803 |
|
|
}
|
804 |
|
|
|
805 |
|
|
$export_key = $this->plugin['export']['key'];
|
806 |
|
|
|
807 |
|
|
|
808 |
|
|
|
809 |
|
|
if ($form_state['form type'] == 'clone') {
|
810 |
|
|
$name = $form_state['original name'];
|
811 |
|
|
}
|
812 |
|
|
else {
|
813 |
|
|
$name = $form_state['item']->{$export_key};
|
814 |
|
|
}
|
815 |
|
|
|
816 |
|
|
$form_info = !empty($this->plugin['form info']) ? $this->plugin['form info'] : array();
|
817 |
|
|
$form_info += array(
|
818 |
|
|
'id' => 'ctools_export_ui_edit',
|
819 |
|
|
'path' => ctools_export_ui_plugin_menu_path($this->plugin, $form_state['form type'], $name) . '/%step',
|
820 |
|
|
'show trail' => TRUE,
|
821 |
|
|
'free trail' => TRUE,
|
822 |
|
|
'show back' => $form_state['form type'] == 'add',
|
823 |
|
|
'show return' => FALSE,
|
824 |
|
|
'show cancel' => TRUE,
|
825 |
|
|
'finish callback' => 'ctools_export_ui_wizard_finish',
|
826 |
|
|
'next callback' => 'ctools_export_ui_wizard_next',
|
827 |
|
|
'back callback' => 'ctools_export_ui_wizard_back',
|
828 |
|
|
'cancel callback' => 'ctools_export_ui_wizard_cancel',
|
829 |
|
|
'order' => array(),
|
830 |
|
|
'import order' => array(
|
831 |
|
|
'import' => t('Import code'),
|
832 |
|
|
'settings' => t('Settings'),
|
833 |
|
|
),
|
834 |
|
|
);
|
835 |
|
|
|
836 |
|
|
|
837 |
|
|
if (isset($form_info[$form_state['form type'] . ' order'])) {
|
838 |
|
|
$form_info['order'] = $form_info[$form_state['form type'] . ' order'];
|
839 |
|
|
}
|
840 |
|
|
|
841 |
|
|
|
842 |
|
|
|
843 |
|
|
|
844 |
|
|
foreach ($form_info['order'] as $key => $title) {
|
845 |
|
|
if (empty($form_info['forms'][$key])) {
|
846 |
|
|
$form_info['forms'][$key] = array(
|
847 |
|
|
'form id' => 'ctools_export_ui_edit_item_wizard_form',
|
848 |
|
|
);
|
849 |
|
|
}
|
850 |
|
|
}
|
851 |
|
|
|
852 |
|
|
|
853 |
|
|
|
854 |
|
|
if ($form_state['form type'] == 'add' || ($form_state['form type'] == 'import' && empty($form_state['item']->{$export_key}))) {
|
855 |
|
|
$form_info['free trail'] = FALSE;
|
856 |
|
|
}
|
857 |
|
|
|
858 |
|
|
return $form_info;
|
859 |
|
|
}
|
860 |
|
|
|
861 |
|
|
|
862 |
|
|
|
863 |
|
|
|
864 |
|
|
|
865 |
|
|
|
866 |
|
|
|
867 |
|
|
|
868 |
|
|
|
869 |
|
|
|
870 |
|
|
|
871 |
|
|
|
872 |
|
|
|
873 |
|
|
|
874 |
|
|
|
875 |
|
|
function edit_execute_form_wizard(&$form_state) {
|
876 |
|
|
$form_info = $this->get_wizard_info($form_state);
|
877 |
|
|
|
878 |
|
|
|
879 |
|
|
if (empty($form_info['order'])) {
|
880 |
|
|
return MENU_NOT_FOUND;
|
881 |
|
|
}
|
882 |
|
|
|
883 |
|
|
|
884 |
|
|
if (empty($form_state['step'])) {
|
885 |
|
|
$order = array_keys($form_info['order']);
|
886 |
|
|
$form_state['step'] = reset($order);
|
887 |
|
|
}
|
888 |
|
|
|
889 |
|
|
if (empty($form_info['order'][$form_state['step']]) && empty($form_info['forms'][$form_state['step']])) {
|
890 |
|
|
return MENU_NOT_FOUND;
|
891 |
|
|
}
|
892 |
|
|
|
893 |
|
|
ctools_include('wizard');
|
894 |
|
|
$output = ctools_wizard_multistep_form($form_info, $form_state['step'], $form_state);
|
895 |
|
|
if (!empty($form_state['complete'])) {
|
896 |
|
|
$this->edit_save_form($form_state);
|
897 |
|
|
}
|
898 |
|
|
else if ($output && !empty($form_state['item']->export_ui_item_is_cached)) {
|
899 |
|
|
|
900 |
|
|
drupal_set_message(t('You have unsaved changes. These changes will not be made permanent until you click <em>Save</em>.'), 'warning');
|
901 |
|
|
}
|
902 |
|
|
|
903 |
|
|
|
904 |
|
|
|
905 |
|
|
if (!empty($form_state['executed']) && empty($form_state['clicked_button']['#wizard type'])) {
|
906 |
|
|
unset($form_state['executed']);
|
907 |
|
|
}
|
908 |
|
|
return $output;
|
909 |
|
|
}
|
910 |
|
|
|
911 |
|
|
|
912 |
|
|
|
913 |
|
|
|
914 |
|
|
|
915 |
|
|
|
916 |
|
|
function edit_wizard_back(&$form_state) {
|
917 |
|
|
|
918 |
|
|
}
|
919 |
|
|
|
920 |
|
|
|
921 |
|
|
|
922 |
|
|
|
923 |
|
|
|
924 |
|
|
|
925 |
|
|
function edit_wizard_next(&$form_state) {
|
926 |
|
|
$this->edit_cache_set($form_state['item'], $form_state['form type']);
|
927 |
|
|
}
|
928 |
|
|
|
929 |
|
|
|
930 |
|
|
|
931 |
|
|
|
932 |
|
|
|
933 |
|
|
|
934 |
|
|
function edit_wizard_cancel(&$form_state) {
|
935 |
|
|
$this->edit_cache_clear($form_state['item'], $form_state['form type']);
|
936 |
|
|
}
|
937 |
|
|
|
938 |
|
|
|
939 |
|
|
|
940 |
|
|
|
941 |
|
|
|
942 |
|
|
|
943 |
|
|
function edit_wizard_finish(&$form_state) {
|
944 |
|
|
$form_state['complete'] = TRUE;
|
945 |
|
|
|
946 |
|
|
|
947 |
|
|
|
948 |
|
|
if ($form_state['form type'] == 'import' && !empty($form_state['item']->export_ui_allow_overwrite)) {
|
949 |
|
|
ctools_export_crud_delete($this->plugin['schema'], $form_state['item']);
|
950 |
|
|
}
|
951 |
|
|
|
952 |
|
|
$this->edit_cache_clear($form_state['item'], $form_state['form type']);
|
953 |
|
|
}
|
954 |
|
|
|
955 |
|
|
|
956 |
|
|
|
957 |
|
|
|
958 |
|
|
function edit_cache_get($item, $op = 'edit') {
|
959 |
|
|
ctools_include('object-cache');
|
960 |
|
|
if (is_string($item)) {
|
961 |
|
|
$name = $item;
|
962 |
|
|
}
|
963 |
|
|
else {
|
964 |
|
|
$name = $this->edit_cache_get_key($item, $op);
|
965 |
|
|
}
|
966 |
|
|
|
967 |
|
|
$cache = ctools_object_cache_get('ctui_' . $this->plugin['name'], $name);
|
968 |
|
|
if ($cache) {
|
969 |
|
|
$cache->export_ui_item_is_cached = TRUE;
|
970 |
|
|
return $cache;
|
971 |
|
|
}
|
972 |
|
|
}
|
973 |
|
|
|
974 |
|
|
|
975 |
|
|
|
976 |
|
|
|
977 |
|
|
function edit_cache_set($item, $op = 'edit') {
|
978 |
|
|
ctools_include('object-cache');
|
979 |
|
|
$name = $this->edit_cache_get_key($item, $op);
|
980 |
|
|
return $this->edit_cache_set_key($item, $name);
|
981 |
|
|
}
|
982 |
|
|
|
983 |
|
|
function edit_cache_set_key($item, $name) {
|
984 |
|
|
return ctools_object_cache_set('ctui_' . $this->plugin['name'], $name, $item);
|
985 |
|
|
}
|
986 |
|
|
|
987 |
|
|
|
988 |
|
|
|
989 |
|
|
|
990 |
|
|
function edit_cache_clear($item, $op = 'edit') {
|
991 |
|
|
ctools_include('object-cache');
|
992 |
|
|
$name = $this->edit_cache_get_key($item, $op);
|
993 |
|
|
return ctools_object_cache_clear('ctui_' . $this->plugin['name'], $name);
|
994 |
|
|
}
|
995 |
|
|
|
996 |
|
|
|
997 |
|
|
|
998 |
|
|
|
999 |
|
|
function edit_cache_get_key($item, $op) {
|
1000 |
|
|
$export_key = $this->plugin['export']['key'];
|
1001 |
|
|
return $op == 'edit' ? $item->{$this->plugin['export']['key']} : "::$op";
|
1002 |
|
|
}
|
1003 |
|
|
|
1004 |
|
|
|
1005 |
|
|
|
1006 |
|
|
|
1007 |
|
|
function edit_save_form($form_state) {
|
1008 |
|
|
$item = &$form_state['item'];
|
1009 |
|
|
$export_key = $this->plugin['export']['key'];
|
1010 |
|
|
|
1011 |
|
|
$result = ctools_export_crud_save($this->plugin['schema'], $item);
|
1012 |
|
|
|
1013 |
|
|
if ($result) {
|
1014 |
|
|
$message = str_replace('%title', check_plain($item->{$export_key}), $this->plugin['strings']['confirmation'][$form_state['op']]['success']);
|
1015 |
|
|
drupal_set_message($message);
|
1016 |
|
|
}
|
1017 |
|
|
else {
|
1018 |
|
|
$message = str_replace('%title', check_plain($item->{$export_key}), $this->plugin['strings']['confirmation'][$form_state['op']]['fail']);
|
1019 |
|
|
drupal_set_message($message, 'error');
|
1020 |
|
|
}
|
1021 |
|
|
}
|
1022 |
|
|
|
1023 |
|
|
|
1024 |
|
|
|
1025 |
|
|
|
1026 |
|
|
function edit_form(&$form, &$form_state) {
|
1027 |
|
|
$export_key = $this->plugin['export']['key'];
|
1028 |
|
|
$item = $form_state['item'];
|
1029 |
|
|
$schema = ctools_export_get_schema($this->plugin['schema']);
|
1030 |
|
|
|
1031 |
|
|
if (!empty($this->plugin['export']['admin_title'])) {
|
1032 |
|
|
$form['info'][$this->plugin['export']['admin_title']] = array(
|
1033 |
|
|
'#type' => 'textfield',
|
1034 |
|
|
'#title' => t('Administrative title'),
|
1035 |
|
|
'#description' => t('This will appear in the administrative interface to easily identify it.'),
|
1036 |
|
|
'#default_value' => $item->{$this->plugin['export']['admin_title']},
|
1037 |
|
|
);
|
1038 |
|
|
}
|
1039 |
|
|
|
1040 |
|
|
$form['info'][$export_key] = array(
|
1041 |
|
|
'#title' => t($schema['export']['key name']),
|
1042 |
|
|
'#type' => 'textfield',
|
1043 |
|
|
'#default_value' => $item->{$export_key},
|
1044 |
|
|
'#description' => t('The unique ID for this @export.', array('@export' => $this->plugin['title singular'])),
|
1045 |
|
|
'#required' => TRUE,
|
1046 |
|
|
'#maxlength' => 255,
|
1047 |
|
|
);
|
1048 |
|
|
|
1049 |
|
|
if (!empty($this->plugin['export']['admin_title'])) {
|
1050 |
|
|
$form['info'][$export_key]['#type'] = 'machine_name';
|
1051 |
|
|
$form['info'][$export_key]['#machine_name'] = array(
|
1052 |
|
|
'exists' => 'ctools_export_ui_edit_name_exists',
|
1053 |
|
|
'source' => array('info', $this->plugin['export']['admin_title']),
|
1054 |
|
|
);
|
1055 |
|
|
}
|
1056 |
|
|
|
1057 |
|
|
if ($form_state['op'] === 'edit') {
|
1058 |
|
|
$form['info'][$export_key]['#disabled'] = TRUE;
|
1059 |
|
|
$form['info'][$export_key]['#value'] = $item->{$export_key};
|
1060 |
|
|
}
|
1061 |
|
|
|
1062 |
|
|
if (!empty($this->plugin['export']['admin_description'])) {
|
1063 |
|
|
$form['info'][$this->plugin['export']['admin_description']] = array(
|
1064 |
|
|
'#type' => 'textarea',
|
1065 |
|
|
'#title' => t('Administrative description'),
|
1066 |
|
|
'#default_value' => $item->{$this->plugin['export']['admin_description']},
|
1067 |
|
|
);
|
1068 |
|
|
}
|
1069 |
|
|
|
1070 |
|
|
|
1071 |
|
|
if (!empty($this->plugin['form']['settings'])) {
|
1072 |
|
|
|
1073 |
|
|
$this->plugin['form']['settings']($form, $form_state);
|
1074 |
|
|
}
|
1075 |
|
|
|
1076 |
|
|
|
1077 |
|
|
if (empty($form_state['form_info'])) {
|
1078 |
|
|
|
1079 |
|
|
$form['buttons']['#weight'] = 100;
|
1080 |
|
|
|
1081 |
|
|
|
1082 |
|
|
$form['buttons']['submit'] = array(
|
1083 |
|
|
'#type' => 'submit',
|
1084 |
|
|
'#value' => t('Save'),
|
1085 |
|
|
);
|
1086 |
|
|
|
1087 |
|
|
$form['buttons']['delete'] = array(
|
1088 |
|
|
'#type' => 'submit',
|
1089 |
|
|
'#value' => $item->export_type & EXPORT_IN_CODE ? t('Revert') : t('Delete'),
|
1090 |
|
|
'#access' => $form_state['op'] === 'edit' && $item->export_type & EXPORT_IN_DATABASE,
|
1091 |
|
|
'#submit' => array('ctools_export_ui_edit_item_form_delete'),
|
1092 |
|
|
);
|
1093 |
|
|
}
|
1094 |
|
|
}
|
1095 |
|
|
|
1096 |
|
|
|
1097 |
|
|
|
1098 |
|
|
|
1099 |
|
|
function edit_form_validate(&$form, &$form_state) {
|
1100 |
|
|
if (!empty($this->plugin['form']['validate'])) {
|
1101 |
|
|
|
1102 |
|
|
$this->plugin['form']['validate']($form, $form_state);
|
1103 |
|
|
}
|
1104 |
|
|
}
|
1105 |
|
|
|
1106 |
|
|
|
1107 |
|
|
|
1108 |
|
|
|
1109 |
|
|
|
1110 |
|
|
function edit_finish_validate(&$form, &$form_state) {
|
1111 |
|
|
if ($form_state['op'] != 'edit') {
|
1112 |
|
|
|
1113 |
|
|
$export_key = $this->plugin['export']['key'];
|
1114 |
|
|
$element = array(
|
1115 |
|
|
'#value' => $form_state['item']->{$export_key},
|
1116 |
|
|
'#parents' => array($export_key),
|
1117 |
|
|
);
|
1118 |
|
|
$form_state['plugin'] = $this->plugin;
|
1119 |
|
|
ctools_export_ui_edit_name_validate($element, $form_state);
|
1120 |
|
|
}
|
1121 |
|
|
}
|
1122 |
|
|
|
1123 |
|
|
|
1124 |
|
|
|
1125 |
|
|
|
1126 |
|
|
|
1127 |
|
|
|
1128 |
|
|
|
1129 |
|
|
|
1130 |
|
|
|
1131 |
|
|
|
1132 |
|
|
function edit_form_submit(&$form, &$form_state) {
|
1133 |
|
|
if (!empty($this->plugin['form']['submit'])) {
|
1134 |
|
|
|
1135 |
|
|
$this->plugin['form']['submit']($form, $form_state);
|
1136 |
|
|
}
|
1137 |
|
|
|
1138 |
|
|
|
1139 |
|
|
$schema = ctools_export_get_schema($this->plugin['schema']);
|
1140 |
|
|
foreach (array_keys($schema['fields']) as $key) {
|
1141 |
|
|
if(isset($form_state['values'][$key])) {
|
1142 |
|
|
$form_state['item']->{$key} = $form_state['values'][$key];
|
1143 |
|
|
}
|
1144 |
|
|
}
|
1145 |
|
|
}
|
1146 |
|
|
|
1147 |
|
|
|
1148 |
|
|
|
1149 |
|
|
|
1150 |
|
|
|
1151 |
|
|
|
1152 |
|
|
|
1153 |
|
|
|
1154 |
|
|
function enable_page($js, $input, $item) {
|
1155 |
|
|
return $this->set_item_state(FALSE, $js, $input, $item);
|
1156 |
|
|
}
|
1157 |
|
|
|
1158 |
|
|
|
1159 |
|
|
|
1160 |
|
|
|
1161 |
|
|
function disable_page($js, $input, $item) {
|
1162 |
|
|
return $this->set_item_state(TRUE, $js, $input, $item);
|
1163 |
|
|
}
|
1164 |
|
|
|
1165 |
|
|
|
1166 |
|
|
|
1167 |
|
|
|
1168 |
|
|
|
1169 |
|
|
|
1170 |
|
|
|
1171 |
|
|
function set_item_state($state, $js, $input, $item) {
|
1172 |
|
|
ctools_export_crud_set_status($this->plugin['schema'], $item, $state);
|
1173 |
|
|
|
1174 |
|
|
if (!$js) {
|
1175 |
|
|
drupal_goto(ctools_export_ui_plugin_base_path($this->plugin));
|
1176 |
|
|
}
|
1177 |
|
|
else {
|
1178 |
|
|
return $this->list_page($js, $input);
|
1179 |
|
|
}
|
1180 |
|
|
}
|
1181 |
|
|
|
1182 |
|
|
|
1183 |
|
|
|
1184 |
|
|
|
1185 |
|
|
function delete_page($js, $input, $item) {
|
1186 |
|
|
$form_state = array(
|
1187 |
|
|
'plugin' => $this->plugin,
|
1188 |
|
|
'object' => &$this,
|
1189 |
|
|
'ajax' => $js,
|
1190 |
|
|
'item' => $item,
|
1191 |
|
|
'op' => $item->export_type & EXPORT_IN_CODE ? 'revert' : 'delete',
|
1192 |
|
|
'rerender' => TRUE,
|
1193 |
|
|
'no_redirect' => TRUE,
|
1194 |
|
|
);
|
1195 |
|
|
|
1196 |
|
|
$output = drupal_build_form('ctools_export_ui_delete_confirm_form', $form_state);
|
1197 |
|
|
if (!empty($form_state['executed'])) {
|
1198 |
|
|
$this->delete_form_submit($form_state);
|
1199 |
|
|
$this->redirect($form_state['op'], $item);
|
1200 |
|
|
}
|
1201 |
|
|
|
1202 |
|
|
return $output;
|
1203 |
|
|
}
|
1204 |
|
|
|
1205 |
|
|
|
1206 |
|
|
|
1207 |
|
|
|
1208 |
|
|
function delete_form_submit(&$form_state) {
|
1209 |
|
|
$item = $form_state['item'];
|
1210 |
|
|
|
1211 |
|
|
ctools_export_crud_delete($this->plugin['schema'], $item);
|
1212 |
|
|
$export_key = $this->plugin['export']['key'];
|
1213 |
|
|
$message = str_replace('%title', check_plain($item->{$export_key}), $this->plugin['strings']['confirmation'][$form_state['op']]['success']);
|
1214 |
|
|
drupal_set_message($message);
|
1215 |
|
|
}
|
1216 |
|
|
|
1217 |
|
|
|
1218 |
|
|
|
1219 |
|
|
|
1220 |
|
|
function export_page($js, $input, $item) {
|
1221 |
e4c061ad
|
Assos Assos
|
drupal_set_title($this->get_page_title('export', $item), PASS_THROUGH);
|
1222 |
85ad3d82
|
Assos Assos
|
return drupal_get_form('ctools_export_form', ctools_export_crud_export($this->plugin['schema'], $item), t('Export'));
|
1223 |
|
|
}
|
1224 |
|
|
|
1225 |
|
|
|
1226 |
|
|
|
1227 |
|
|
|
1228 |
|
|
function import_page($js, $input, $step = NULL) {
|
1229 |
e4c061ad
|
Assos Assos
|
drupal_set_title($this->get_page_title('import'), PASS_THROUGH);
|
1230 |
85ad3d82
|
Assos Assos
|
|
1231 |
|
|
|
1232 |
|
|
|
1233 |
|
|
|
1234 |
|
|
|
1235 |
|
|
if (!empty($step)) {
|
1236 |
|
|
$item = $this->edit_cache_get(NULL, 'import');
|
1237 |
|
|
}
|
1238 |
|
|
if (empty($item)) {
|
1239 |
|
|
$item = ctools_export_crud_new($this->plugin['schema']);
|
1240 |
|
|
}
|
1241 |
|
|
|
1242 |
|
|
$form_state = array(
|
1243 |
|
|
'plugin' => $this->plugin,
|
1244 |
|
|
'object' => &$this,
|
1245 |
|
|
'ajax' => $js,
|
1246 |
|
|
'item' => $item,
|
1247 |
|
|
'op' => 'add',
|
1248 |
|
|
'form type' => 'import',
|
1249 |
|
|
'rerender' => TRUE,
|
1250 |
|
|
'no_redirect' => TRUE,
|
1251 |
|
|
'step' => $step,
|
1252 |
|
|
|
1253 |
|
|
'function args' => func_get_args(),
|
1254 |
|
|
);
|
1255 |
|
|
|
1256 |
|
|
|
1257 |
|
|
$output = $this->edit_execute_form_wizard($form_state);
|
1258 |
|
|
if (!empty($form_state['executed'])) {
|
1259 |
|
|
$this->redirect($form_state['op'], $form_state['item']);
|
1260 |
|
|
}
|
1261 |
|
|
|
1262 |
|
|
return $output;
|
1263 |
|
|
}
|
1264 |
|
|
|
1265 |
|
|
|
1266 |
|
|
|
1267 |
|
|
|
1268 |
|
|
|
1269 |
|
|
function edit_form_import(&$form, &$form_state) {
|
1270 |
|
|
$form['help'] = array(
|
1271 |
|
|
'#type' => 'item',
|
1272 |
|
|
'#value' => $this->plugin['strings']['help']['import'],
|
1273 |
|
|
);
|
1274 |
|
|
|
1275 |
|
|
$form['import'] = array(
|
1276 |
|
|
'#title' => t('@plugin code', array('@plugin' => $this->plugin['title singular proper'])),
|
1277 |
|
|
'#type' => 'textarea',
|
1278 |
|
|
'#rows' => 10,
|
1279 |
|
|
'#required' => TRUE,
|
1280 |
|
|
'#default_value' => !empty($form_state['item']->export_ui_code) ? $form_state['item']->export_ui_code : '',
|
1281 |
|
|
);
|
1282 |
|
|
|
1283 |
|
|
$form['overwrite'] = array(
|
1284 |
|
|
'#title' => t('Allow import to overwrite an existing record.'),
|
1285 |
|
|
'#type' => 'checkbox',
|
1286 |
|
|
'#default_value' => !empty($form_state['item']->export_ui_allow_overwrite) ? $form_state['item']->export_ui_allow_overwrite : FALSE,
|
1287 |
|
|
);
|
1288 |
|
|
}
|
1289 |
|
|
|
1290 |
|
|
|
1291 |
|
|
|
1292 |
|
|
|
1293 |
|
|
|
1294 |
|
|
|
1295 |
|
|
function edit_form_import_validate($form, &$form_state) {
|
1296 |
|
|
$item = ctools_export_crud_import($this->plugin['schema'], $form_state['values']['import']);
|
1297 |
|
|
if (is_string($item)) {
|
1298 |
|
|
form_error($form['import'], t('Unable to get an import from the code. Errors reported: @errors', array('@errors' => $item)));
|
1299 |
|
|
return;
|
1300 |
|
|
}
|
1301 |
|
|
|
1302 |
|
|
$form_state['item'] = $item;
|
1303 |
|
|
$form_state['item']->export_ui_allow_overwrite = $form_state['values']['overwrite'];
|
1304 |
|
|
$form_state['item']->export_ui_code = $form_state['values']['import'];
|
1305 |
|
|
}
|
1306 |
|
|
|
1307 |
|
|
|
1308 |
|
|
|
1309 |
|
|
|
1310 |
|
|
|
1311 |
|
|
|
1312 |
|
|
function edit_form_import_submit($form, &$form_state) {
|
1313 |
|
|
|
1314 |
|
|
|
1315 |
|
|
|
1316 |
|
|
}
|
1317 |
|
|
}
|
1318 |
|
|
|
1319 |
|
|
|
1320 |
|
|
|
1321 |
|
|
|
1322 |
|
|
|
1323 |
|
|
|
1324 |
|
|
|
1325 |
|
|
|
1326 |
|
|
|
1327 |
|
|
|
1328 |
|
|
|
1329 |
|
|
function _ctools_export_ui_add_form_files($form, &$form_state) {
|
1330 |
|
|
ctools_form_include($form_state, 'export');
|
1331 |
|
|
ctools_form_include($form_state, 'export-ui');
|
1332 |
|
|
|
1333 |
|
|
|
1334 |
|
|
ctools_form_include_file($form_state, $form_state['object']->plugin['path'] . '/' . $form_state['object']->plugin['file']);
|
1335 |
|
|
}
|
1336 |
|
|
|
1337 |
|
|
|
1338 |
|
|
|
1339 |
|
|
|
1340 |
|
|
|
1341 |
|
|
|
1342 |
e4c061ad
|
Assos Assos
|
function ctools_export_ui_list_form($form, &$form_state) {
|
1343 |
85ad3d82
|
Assos Assos
|
$form_state['object']->list_form($form, $form_state);
|
1344 |
|
|
return $form;
|
1345 |
|
|
}
|
1346 |
|
|
|
1347 |
|
|
|
1348 |
|
|
|
1349 |
|
|
|
1350 |
|
|
function ctools_export_ui_list_form_validate(&$form, &$form_state) {
|
1351 |
|
|
$form_state['object']->list_form_validate($form, $form_state);
|
1352 |
|
|
}
|
1353 |
|
|
|
1354 |
|
|
|
1355 |
|
|
|
1356 |
|
|
|
1357 |
|
|
function ctools_export_ui_list_form_submit(&$form, &$form_state) {
|
1358 |
|
|
$form_state['object']->list_form_submit($form, $form_state);
|
1359 |
|
|
}
|
1360 |
|
|
|
1361 |
|
|
|
1362 |
|
|
|
1363 |
|
|
|
1364 |
|
|
|
1365 |
|
|
|
1366 |
|
|
function ctools_export_ui_edit_item_form($form, &$form_state) {
|
1367 |
|
|
|
1368 |
|
|
|
1369 |
|
|
_ctools_export_ui_add_form_files($form, $form_state);
|
1370 |
|
|
|
1371 |
|
|
$form_state['object']->edit_form($form, $form_state);
|
1372 |
|
|
return $form;
|
1373 |
|
|
}
|
1374 |
|
|
|
1375 |
|
|
|
1376 |
|
|
|
1377 |
|
|
|
1378 |
|
|
function ctools_export_ui_edit_item_form_validate(&$form, &$form_state) {
|
1379 |
|
|
$form_state['object']->edit_form_validate($form, $form_state);
|
1380 |
|
|
}
|
1381 |
|
|
|
1382 |
|
|
|
1383 |
|
|
|
1384 |
|
|
|
1385 |
|
|
function ctools_export_ui_edit_item_form_submit(&$form, &$form_state) {
|
1386 |
|
|
$form_state['object']->edit_form_submit($form, $form_state);
|
1387 |
|
|
}
|
1388 |
|
|
|
1389 |
|
|
|
1390 |
|
|
|
1391 |
|
|
|
1392 |
|
|
|
1393 |
|
|
|
1394 |
|
|
function ctools_export_ui_edit_item_form_delete(&$form, &$form_state) {
|
1395 |
|
|
_ctools_export_ui_add_form_files($form, $form_state);
|
1396 |
|
|
|
1397 |
|
|
$export_key = $form_state['plugin']['export']['key'];
|
1398 |
|
|
$path = $form_state['item']->export_type & EXPORT_IN_CODE ? 'revert' : 'delete';
|
1399 |
|
|
|
1400 |
|
|
drupal_goto(ctools_export_ui_plugin_menu_path($form_state['plugin'], $path, $form_state['item']->{$export_key}), array('cancel_path' => $_GET['q']));
|
1401 |
|
|
}
|
1402 |
|
|
|
1403 |
|
|
|
1404 |
|
|
|
1405 |
|
|
|
1406 |
|
|
function ctools_export_ui_edit_name_validate($element, &$form_state) {
|
1407 |
|
|
$plugin = $form_state['plugin'];
|
1408 |
|
|
|
1409 |
|
|
if (!preg_match('!^[a-z0-9_]+$!', $element['#value'])) {
|
1410 |
|
|
form_error($element, t('The export id can only consist of lowercase letters, underscores, and numbers.'));
|
1411 |
|
|
return;
|
1412 |
|
|
}
|
1413 |
|
|
|
1414 |
|
|
|
1415 |
|
|
if (empty($form_state['item']->export_ui_allow_overwrite) && $exists = ctools_export_crud_load($plugin['schema'], $element['#value'])) {
|
1416 |
|
|
form_error($element, t('A @plugin with this name already exists. Please choose another name or delete the existing item before creating a new one.', array('@plugin' => $plugin['title singular'])));
|
1417 |
|
|
}
|
1418 |
|
|
}
|
1419 |
|
|
|
1420 |
|
|
|
1421 |
|
|
|
1422 |
|
|
|
1423 |
|
|
function ctools_export_ui_edit_name_exists($name, $element, &$form_state) {
|
1424 |
|
|
$plugin = $form_state['plugin'];
|
1425 |
|
|
|
1426 |
|
|
return (empty($form_state['item']->export_ui_allow_overwrite) && ctools_export_crud_load($plugin['schema'], $name));
|
1427 |
|
|
}
|
1428 |
|
|
|
1429 |
|
|
|
1430 |
|
|
|
1431 |
|
|
|
1432 |
|
|
|
1433 |
|
|
|
1434 |
|
|
function ctools_export_ui_delete_confirm_form($form, &$form_state) {
|
1435 |
|
|
_ctools_export_ui_add_form_files($form, $form_state);
|
1436 |
|
|
|
1437 |
|
|
$plugin = $form_state['plugin'];
|
1438 |
|
|
$item = $form_state['item'];
|
1439 |
|
|
|
1440 |
|
|
$form = array();
|
1441 |
|
|
|
1442 |
|
|
$export_key = $plugin['export']['key'];
|
1443 |
|
|
$question = str_replace('%title', check_plain($item->{$export_key}), $plugin['strings']['confirmation'][$form_state['op']]['question']);
|
1444 |
c22e192e
|
Assos Assos
|
$path = (!empty($_REQUEST['cancel_path']) && !url_is_external($_REQUEST['cancel_path'])) ? $_REQUEST['cancel_path'] : ctools_export_ui_plugin_base_path($plugin);
|
1445 |
85ad3d82
|
Assos Assos
|
|
1446 |
|
|
$form = confirm_form($form,
|
1447 |
|
|
$question,
|
1448 |
|
|
$path,
|
1449 |
|
|
$plugin['strings']['confirmation'][$form_state['op']]['information'],
|
1450 |
|
|
$plugin['allowed operations'][$form_state['op']]['title'], t('Cancel')
|
1451 |
|
|
);
|
1452 |
|
|
return $form;
|
1453 |
|
|
}
|
1454 |
|
|
|
1455 |
|
|
|
1456 |
|
|
|
1457 |
|
|
|
1458 |
|
|
|
1459 |
|
|
|
1460 |
|
|
|
1461 |
|
|
|
1462 |
|
|
|
1463 |
|
|
function ctools_export_ui_edit_item_wizard_form($form, &$form_state) {
|
1464 |
|
|
_ctools_export_ui_add_form_files($form, $form_state);
|
1465 |
|
|
|
1466 |
|
|
$method = 'edit_form_' . $form_state['step'];
|
1467 |
|
|
if (!method_exists($form_state['object'], $method)) {
|
1468 |
|
|
$method = 'edit_form';
|
1469 |
|
|
}
|
1470 |
|
|
|
1471 |
|
|
$form_state['object']->$method($form, $form_state);
|
1472 |
|
|
return $form;
|
1473 |
|
|
}
|
1474 |
|
|
|
1475 |
|
|
|
1476 |
|
|
|
1477 |
|
|
|
1478 |
|
|
function ctools_export_ui_edit_item_wizard_form_validate(&$form, &$form_state) {
|
1479 |
|
|
$method = 'edit_form_' . $form_state['step'] . '_validate';
|
1480 |
|
|
if (!method_exists($form_state['object'], $method)) {
|
1481 |
|
|
$method = 'edit_form_validate';
|
1482 |
|
|
}
|
1483 |
|
|
|
1484 |
|
|
$form_state['object']->$method($form, $form_state);
|
1485 |
|
|
|
1486 |
|
|
|
1487 |
|
|
|
1488 |
|
|
if (isset($form_state['clicked_button']['#wizard type']) && $form_state['clicked_button']['#wizard type'] == 'finish' && !form_get_errors()) {
|
1489 |
|
|
$form_state['object']->edit_finish_validate($form, $form_state);
|
1490 |
|
|
}
|
1491 |
|
|
}
|
1492 |
|
|
|
1493 |
|
|
|
1494 |
|
|
|
1495 |
|
|
|
1496 |
|
|
function ctools_export_ui_edit_item_wizard_form_submit(&$form, &$form_state) {
|
1497 |
|
|
$method = 'edit_form_' . $form_state['step'] . '_submit';
|
1498 |
|
|
if (!method_exists($form_state['object'], $method)) {
|
1499 |
|
|
$method = 'edit_form_submit';
|
1500 |
|
|
}
|
1501 |
|
|
|
1502 |
|
|
$form_state['object']->$method($form, $form_state);
|
1503 |
|
|
}
|
1504 |
|
|
|
1505 |
|
|
|
1506 |
|
|
|
1507 |
|
|
|
1508 |
|
|
function ctools_export_ui_wizard_back(&$form_state) {
|
1509 |
|
|
$form_state['object']->edit_wizard_back($form_state);
|
1510 |
|
|
}
|
1511 |
|
|
|
1512 |
|
|
|
1513 |
|
|
|
1514 |
|
|
|
1515 |
|
|
function ctools_export_ui_wizard_next(&$form_state) {
|
1516 |
|
|
$form_state['object']->edit_wizard_next($form_state);
|
1517 |
|
|
}
|
1518 |
|
|
|
1519 |
|
|
|
1520 |
|
|
|
1521 |
|
|
|
1522 |
|
|
function ctools_export_ui_wizard_cancel(&$form_state) {
|
1523 |
|
|
$form_state['object']->edit_wizard_cancel($form_state);
|
1524 |
|
|
}
|
1525 |
|
|
|
1526 |
|
|
|
1527 |
|
|
|
1528 |
|
|
|
1529 |
|
|
function ctools_export_ui_wizard_finish(&$form_state) {
|
1530 |
|
|
$form_state['object']->edit_wizard_finish($form_state);
|
1531 |
|
|
} |