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
|
|
39
|
|
40
|
if ($this->plugin['menu']['items'][$key]['access callback'] == 'panelizer_has_choice_callback') {
|
41
|
continue;
|
42
|
}
|
43
|
|
44
|
$this->plugin['menu']['items'][$key]['access callback'] = 'panelizer_has_choice_callback';
|
45
|
$this->plugin['menu']['items'][$key]['access arguments'] = array(3, 4, '');
|
46
|
$this->plugin['menu']['items'][$key]['page callback'] = 'panelizer_export_ui_switcher_page';
|
47
|
array_unshift($this->plugin['menu']['items'][$key]['page arguments'], 4);
|
48
|
array_unshift($this->plugin['menu']['items'][$key]['page arguments'], 3);
|
49
|
}
|
50
|
|
51
|
parent::hook_menu($items);
|
52
|
}
|
53
|
|
54
|
function list_page($js, $input) {
|
55
|
if ($substitute = $this->entity_handler->get_substitute($this->entity_view_mode, $this->entity_bundle)) {
|
56
|
$url = $this->plugin['menu']['menu prefix'] . '/' . $substitute;
|
57
|
drupal_set_message(t('This display is managed by the !view_mode display.', array('!view_mode' => l($substitute, $url))), 'status', FALSE);
|
58
|
return '';
|
59
|
}
|
60
|
|
61
|
drupal_set_title($this->entity_handler->get_bundle_title($this->entity_bundle));
|
62
|
return parent::list_page($js, $input);
|
63
|
}
|
64
|
|
65
|
function list_filter($form_state, $item) {
|
66
|
|
67
|
if ($this->entity_handler->entity_type != $item->panelizer_type) {
|
68
|
return TRUE;
|
69
|
}
|
70
|
if ($this->entity_bundle != $item->panelizer_key) {
|
71
|
return TRUE;
|
72
|
}
|
73
|
|
74
|
if ($this->entity_view_mode != $item->view_mode) {
|
75
|
return TRUE;
|
76
|
}
|
77
|
|
78
|
if (!$this->entity_handler->access_default_panelizer_object($item)) {
|
79
|
return TRUE;
|
80
|
}
|
81
|
|
82
|
if (empty($item->title) && $item->name == implode(':', array($this->entity_handler->entity_type, $this->entity_bundle, 'default'))) {
|
83
|
$item->title = t('Default');
|
84
|
}
|
85
|
|
86
|
return parent::list_filter($form_state, $item);
|
87
|
}
|
88
|
|
89
|
|
90
|
|
91
|
|
92
|
|
93
|
|
94
|
|
95
|
function edit_form(&$form, &$form_state) {
|
96
|
parent::edit_form($form, $form_state);
|
97
|
foreach ($form['info'] as $export_key => $settings) {
|
98
|
if (!empty($form['info'][$export_key]['#machine_name']['exists'])) {
|
99
|
$form['info'][$export_key]['#machine_name']['exists'] = 'panelizer_defaults_ui_edit_name_exists';
|
100
|
}
|
101
|
}
|
102
|
}
|
103
|
|
104
|
function edit_execute_form_standard(&$form_state) {
|
105
|
if ($form_state['form type'] == 'clone') {
|
106
|
$form_state['item']->title = t('Clone of') . ' ' . $form_state['item']->title;
|
107
|
$form_state['item']->name = '';
|
108
|
}
|
109
|
else if ($form_state['op'] == 'add') {
|
110
|
$form_state['item']->panelizer_type = $this->entity_handler->entity_type;
|
111
|
$form_state['item']->panelizer_key = $this->entity_bundle;
|
112
|
$form_state['item']->view_mode = $this->entity_view_mode;
|
113
|
$form_state['item']->display = $this->entity_handler->get_default_display($this->entity_bundle, $this->entity_view_mode);
|
114
|
}
|
115
|
return parent::edit_execute_form_standard($form_state);
|
116
|
}
|
117
|
|
118
|
function edit_form_validate(&$form, &$form_state) {
|
119
|
|
120
|
|
121
|
$export_key = $this->plugin['export']['key'];
|
122
|
$name = panelizer_defaults_ui_build_export_name($form_state['values'][$export_key], $this);
|
123
|
|
124
|
form_set_value($form['info'][$export_key], $name, $form_state);
|
125
|
}
|
126
|
|
127
|
|
128
|
|
129
|
function delete_page($js, $input, $item) {
|
130
|
$clone = clone $item;
|
131
|
|
132
|
|
133
|
$clone->name = $clone->title;
|
134
|
$form_state = array(
|
135
|
'plugin' => $this->plugin,
|
136
|
'object' => &$this,
|
137
|
'ajax' => $js,
|
138
|
'item' => $clone,
|
139
|
'op' => $item->export_type & EXPORT_IN_CODE ? 'revert' : 'delete',
|
140
|
'rerender' => TRUE,
|
141
|
'no_redirect' => TRUE,
|
142
|
);
|
143
|
|
144
|
$output = drupal_build_form('ctools_export_ui_delete_confirm_form', $form_state);
|
145
|
if (!empty($form_state['executed'])) {
|
146
|
ctools_export_crud_delete($this->plugin['schema'], $item);
|
147
|
$export_key = $this->plugin['export']['key'];
|
148
|
drupal_set_message(t($this->plugin['strings']['confirmation'][$form_state['op']]['success'], array('%title' => $item->title)));
|
149
|
drupal_goto(ctools_export_ui_plugin_base_path($this->plugin));
|
150
|
}
|
151
|
|
152
|
return $output;
|
153
|
}
|
154
|
}
|
155
|
|
156
|
|
157
|
|
158
|
|
159
|
function panelizer_defaults_ui_edit_name_exists($name, $element, &$form_state) {
|
160
|
|
161
|
$export_key = $form_state['plugin']['export']['key'];
|
162
|
$name = panelizer_defaults_ui_build_export_name($form_state['values'][$export_key], $form_state['object']);
|
163
|
|
164
|
|
165
|
return ctools_export_ui_edit_name_exists($name, $element, $form_state);
|
166
|
}
|
167
|
|
168
|
|
169
|
|
170
|
|
171
|
function panelizer_defaults_ui_build_export_name($machine_name, $object) {
|
172
|
|
173
|
|
174
|
|
175
|
$name = implode(':', array(
|
176
|
$object->entity_handler->entity_type,
|
177
|
$object->entity_bundle,
|
178
|
$machine_name
|
179
|
));
|
180
|
|
181
|
|
182
|
|
183
|
if ($object->entity_view_mode != 'page_manager') {
|
184
|
$name .= ':' . $object->entity_view_mode;
|
185
|
}
|
186
|
|
187
|
return $name;
|
188
|
}
|