1
|
<?php
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
class panelizer_defaults_ui extends ctools_export_ui {
|
8
|
function init($plugin) {
|
9
|
ctools_include('export');
|
10
|
|
11
|
$this->plugin = $plugin;
|
12
|
|
13
|
unset($this->plugin['menu']['items']['list callback']);
|
14
|
}
|
15
|
|
16
|
function hook_menu(&$items) {
|
17
|
|
18
|
$this->plugin['menu']['items']['list']['type'] = MENU_LOCAL_TASK;
|
19
|
$this->plugin['menu']['items']['list']['weight'] = -6;
|
20
|
$this->plugin['menu']['items']['list']['title'] = 'List defaults';
|
21
|
|
22
|
|
23
|
$this->plugin['menu']['items']['add']['path'] = 'list/add';
|
24
|
$this->plugin['menu']['items']['import']['path'] = 'list/import';
|
25
|
|
26
|
|
27
|
unset($this->plugin['menu']['items']['edit callback']);
|
28
|
unset($this->plugin['menu']['items']['access']);
|
29
|
foreach (panelizer_operations() as $path => $operation) {
|
30
|
$location = isset($operation['ui path']) ? $operation['ui path'] : $path;
|
31
|
if (isset($this->plugin['menu']['items'][$location])) {
|
32
|
unset($this->plugin['menu']['items'][$location]);
|
33
|
}
|
34
|
}
|
35
|
|
36
|
|
37
|
foreach ($this->plugin['menu']['items'] as $key => $item) {
|
38
|
$this->plugin['menu']['items'][$key]['access callback'] = 'panelizer_has_choice_callback';
|
39
|
$this->plugin['menu']['items'][$key]['access arguments'] = array(4, 5, '');
|
40
|
$this->plugin['menu']['items'][$key]['page callback'] = 'panelizer_export_ui_switcher_page';
|
41
|
array_unshift($this->plugin['menu']['items'][$key]['page arguments'], 5);
|
42
|
array_unshift($this->plugin['menu']['items'][$key]['page arguments'], 4);
|
43
|
}
|
44
|
|
45
|
parent::hook_menu($items);
|
46
|
}
|
47
|
|
48
|
function list_page($js, $input) {
|
49
|
drupal_set_title($this->entity_handler->get_bundle_title($this->entity_bundle));
|
50
|
return parent::list_page($js, $input);
|
51
|
}
|
52
|
|
53
|
function list_filter($form_state, $item) {
|
54
|
|
55
|
if ($this->entity_handler->entity_type != $item->panelizer_type) {
|
56
|
return TRUE;
|
57
|
}
|
58
|
if ($this->entity_bundle != $item->panelizer_key) {
|
59
|
return TRUE;
|
60
|
}
|
61
|
|
62
|
if ($this->entity_view_mode != $item->view_mode) {
|
63
|
return TRUE;
|
64
|
}
|
65
|
|
66
|
if (!$this->entity_handler->access_default_panelizer_object($item)) {
|
67
|
return TRUE;
|
68
|
}
|
69
|
|
70
|
if (empty($item->title) && $item->name == implode(':', array($this->entity_handler->entity_type, $this->entity_bundle, 'default'))) {
|
71
|
$item->title = t('Default');
|
72
|
}
|
73
|
|
74
|
return parent::list_filter($form_state, $item);
|
75
|
}
|
76
|
|
77
|
function edit_execute_form_standard(&$form_state) {
|
78
|
if ($form_state['form type'] == 'clone') {
|
79
|
list($x, $y, $name) = explode(':', $form_state['original name']);
|
80
|
$form_state['item']->title = t('Clone of') . ' ' . $form_state['item']->title;
|
81
|
$form_state['item']->name = 'clone_of_' . $name;
|
82
|
}
|
83
|
else if ($form_state['op'] == 'add') {
|
84
|
$form_state['item']->panelizer_type = $this->entity_handler->entity_type;
|
85
|
$form_state['item']->panelizer_key = $this->entity_bundle;
|
86
|
$form_state['item']->view_mode = $this->entity_view_mode;
|
87
|
$form_state['item']->display = $this->entity_handler->get_default_display($this->entity_bundle, $this->entity_view_mode);
|
88
|
}
|
89
|
return parent::edit_execute_form_standard($form_state);
|
90
|
}
|
91
|
|
92
|
function edit_form_validate(&$form, &$form_state) {
|
93
|
$export_key = $this->plugin['export']['key'];
|
94
|
|
95
|
|
96
|
$name = $form_state['values'][$export_key];
|
97
|
|
98
|
form_set_value($form['info'][$export_key], implode(':', array($this->entity_handler->entity_type, $this->entity_bundle, $name)), $form_state);
|
99
|
}
|
100
|
|
101
|
|
102
|
|
103
|
function delete_page($js, $input, $item) {
|
104
|
$clone = clone($item);
|
105
|
|
106
|
|
107
|
|
108
|
$clone->name = $clone->title;
|
109
|
$form_state = array(
|
110
|
'plugin' => $this->plugin,
|
111
|
'object' => &$this,
|
112
|
'ajax' => $js,
|
113
|
'item' => $clone,
|
114
|
'op' => $item->export_type & EXPORT_IN_CODE ? 'revert' : 'delete',
|
115
|
'rerender' => TRUE,
|
116
|
'no_redirect' => TRUE,
|
117
|
);
|
118
|
|
119
|
$output = drupal_build_form('ctools_export_ui_delete_confirm_form', $form_state);
|
120
|
if (!empty($form_state['executed'])) {
|
121
|
ctools_export_crud_delete($this->plugin['schema'], $item);
|
122
|
$export_key = $this->plugin['export']['key'];
|
123
|
$message = str_replace('%title', check_plain($item->title), $this->plugin['strings']['confirmation'][$form_state['op']]['success']);
|
124
|
drupal_set_message($message);
|
125
|
drupal_goto(ctools_export_ui_plugin_base_path($this->plugin) . '/list');
|
126
|
}
|
127
|
|
128
|
return $output;
|
129
|
}
|
130
|
}
|