Stripping CVS keywords
[project/panels.git] / panels_mini / plugins / export_ui / panels_mini_ui.class.php
CommitLineData
b0d171fd 1<?php
b0d171fd
EM
2
3class panels_mini_ui extends ctools_export_ui {
d22e5fdc
EM
4 function init($plugin) {
5 parent::init($plugin);
6 ctools_include('context');
7 }
8
b0d171fd
EM
9 function list_form(&$form, &$form_state) {
10 ctools_include('plugins', 'panels');
11 $this->layouts = panels_get_layouts();
12
13 parent::list_form($form, $form_state);
14
15 $categories = $layouts = array('all' => t('- All -'));
16 foreach ($this->items as $item) {
17 $categories[$item->category] = $item->category ? $item->category : t('Mini panels');
18 }
19
20 $form['top row']['category'] = array(
21 '#type' => 'select',
22 '#title' => t('Category'),
23 '#options' => $categories,
24 '#default_value' => 'all',
25 '#weight' => -10,
26 );
27
28 foreach ($this->layouts as $name => $plugin) {
29 $layouts[$name] = $plugin['title'];
30 }
31
32 $form['top row']['layout'] = array(
33 '#type' => 'select',
34 '#title' => t('Layout'),
35 '#options' => $layouts,
36 '#default_value' => 'all',
37 '#weight' => -9,
38 );
39 }
40
41 function list_filter($form_state, $item) {
42 if ($form_state['values']['category'] != 'all' && $form_state['values']['category'] != $item->category) {
43 return TRUE;
44 }
45
46 if ($form_state['values']['layout'] != 'all' && $form_state['values']['layout'] != $item->display->layout) {
47 return TRUE;
48 }
49
50 return parent::list_filter($form_state, $item);
51 }
52
53 function list_sort_options() {
54 return array(
55 'disabled' => t('Enabled, title'),
56 'title' => t('Title'),
57 'name' => t('Name'),
58 'category' => t('Category'),
59 'storage' => t('Storage'),
60 'layout' => t('Layout'),
61 );
62 }
63
64 function list_build_row($item, &$form_state, $operations) {
65 // Set up sorting
66 switch ($form_state['values']['order']) {
67 case 'disabled':
50fb37ca 68 $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
b0d171fd
EM
69 break;
70 case 'title':
71 $this->sorts[$item->name] = $item->admin_title;
72 break;
73 case 'name':
74 $this->sorts[$item->name] = $item->name;
75 break;
76 case 'category':
77 $this->sorts[$item->name] = ($item->category ? $item->category : t('Mini panels')) . $item->admin_title;
78 break;
79 case 'layout':
80 $this->sorts[$item->name] = $item->display->layout . $item->admin_title;
81 break;
82 case 'storage':
83 $this->sorts[$item->name] = $item->type . $item->admin_title;
84 break;
85 }
86
87 $layout = !empty($this->layouts[$item->display->layout]) ? $this->layouts[$item->display->layout]['title'] : t('Missing layout');
88 $category = $item->category ? check_plain($item->category) : t('Mini panels');
89
90 $this->rows[$item->name] = array(
91 'data' => array(
50fb37ca 92 array('data' => check_plain($item->admin_title), 'class' => 'ctools-export-ui-title'),
b0d171fd
EM
93 array('data' => check_plain($item->name), 'class' => 'ctools-export-ui-name'),
94 array('data' => $category, 'class' => 'ctools-export-ui-category'),
95 array('data' => $layout, 'class' => 'ctools-export-ui-layout'),
96 array('data' => $item->type, 'class' => 'ctools-export-ui-storage'),
97 array('data' => theme('links', $operations), 'class' => 'ctools-export-ui-operations'),
98 ),
99 'title' => !empty($item->admin_description) ? check_plain($item->admin_description) : '',
100 'class' => !empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled',
101 );
102 }
103
104 function list_table_header() {
105 return array(
106 array('data' => t('Title'), 'class' => 'ctools-export-ui-title'),
107 array('data' => t('Name'), 'class' => 'ctools-export-ui-name'),
108 array('data' => t('Category'), 'class' => 'ctools-export-ui-category'),
109 array('data' => t('Layout'), 'class' => 'ctools-export-ui-layout'),
110 array('data' => t('Storage'), 'class' => 'ctools-export-ui-storage'),
111 array('data' => t('Operations'), 'class' => 'ctools-export-ui-operations'),
112 );
113 }
114
115 function edit_form(&$form, &$form_state) {
116 // Get the basic edit form
117 parent::edit_form($form, $form_state);
118
119 $form['category'] = array(
120 '#type' => 'textfield',
121 '#size' => 24,
122 '#default_value' => $form_state['item']->category,
123 '#title' => t('Category'),
124 '#description' => t("The category that this mini-panel will be grouped into on the Add Content form. Only upper and lower-case alphanumeric characters are allowed. If left blank, defaults to 'Mini panels'."),
125 );
126
127 $form['title']['#title'] = t('Title');
128 $form['title']['#description'] = t('The title for this mini panel. It can be overridden in the block configuration.');
129 }
130
131 /**
132 * Validate submission of the mini panel edit form.
133 */
5f37de7e 134 function edit_form_basic_validate($form, &$form_state) {
b0d171fd
EM
135 parent::edit_form_validate($form, $form_state);
136 if (preg_match("/[^A-Za-z0-9 ]/", $form_state['values']['category'])) {
137 form_error($form['category'], t('Categories may contain only alphanumerics or spaces.'));
138 }
139 }
140
141 function edit_form_submit(&$form, &$form_state) {
142 parent::edit_form_submit($form, $form_state);
143 $form_state['item']->category = $form_state['values']['category'];
144 }
145
146 function edit_form_context(&$form, &$form_state) {
147 ctools_include('context-admin');
148 ctools_context_admin_includes();
149 ctools_add_css('ruleset');
150
151 $form['right'] = array(
152 '#prefix' => '<div class="ctools-right-container">',
153 '#suffix' => '</div>',
154 );
155
156 $form['left'] = array(
157 '#prefix' => '<div class="ctools-left-container clear-block">',
158 '#suffix' => '</div>',
159 );
160
161 // Set this up and we can use CTools' Export UI's built in wizard caching,
162 // which already has callbacks for the context cache under this name.
163 $module = 'ctools_export_ui-' . $this->plugin['name'];
5f37de7e 164 $name = $this->edit_cache_get_key($form_state['item'], $form_state['form type']);
b0d171fd
EM
165
166 ctools_context_add_context_form($module, $form, $form_state, $form['right']['contexts_table'], $form_state['item'], $name);
167 ctools_context_add_required_context_form($module, $form, $form_state, $form['left']['required_contexts_table'], $form_state['item'], $name);
168 ctools_context_add_relationship_form($module, $form, $form_state, $form['right']['relationships_table'], $form_state['item'], $name);
169 }
170
72436b0e
EM
171 function edit_form_context_submit(&$form, &$form_state) {
172 // Prevent this from going to edit_form_submit();
173 }
174
b0d171fd
EM
175 function edit_form_layout(&$form, &$form_state) {
176 ctools_include('common', 'panels');
177 ctools_include('display-layout', 'panels');
178 ctools_include('plugins', 'panels');
179
180 // @todo -- figure out where/how to deal with this.
181 $form_state['allowed_layouts'] = 'panels_mini';
182
72436b0e
EM
183 if ($form_state['op'] == 'add' && empty($form_state['item']->display)) {
184 $form_state['item']->display = panels_new_display();
185 }
186
b0d171fd
EM
187 $form_state['display'] = &$form_state['item']->display;
188
189 // Tell the Panels form not to display buttons.
190 $form_state['no buttons'] = TRUE;
191
192 // Change the #id of the form so the CSS applies properly.
193 $form['#id'] = 'panels-choose-layout';
194 $form = array_merge($form, panels_choose_layout($form_state));
195
72436b0e
EM
196 if ($form_state['op'] == 'edit') {
197 $form['buttons']['next']['#value'] = t('Change');
198 }
b0d171fd
EM
199 }
200
201 /**
202 * Validate that a layout was chosen.
203 */
204 function edit_form_layout_validate(&$form, &$form_state) {
205 $display = &$form_state['display'];
b0d171fd
EM
206 if (empty($form_state['values']['layout'])) {
207 form_error($form['layout'], t('You must select a layout.'));
208 }
72436b0e
EM
209 if ($form_state['op'] == 'edit') {
210 if ($form_state['values']['layout'] == $display->layout) {
211 form_error($form['layout'], t('You must select a different layout if you wish to change layouts.'));
212 }
b0d171fd
EM
213 }
214 }
215
216 /**
217 * A layout has been selected, set it up.
218 */
219 function edit_form_layout_submit(&$form, &$form_state) {
220 $display = &$form_state['display'];
72436b0e
EM
221 if ($form_state['op'] == 'edit') {
222 if ($form_state['values']['layout'] != $display->layout) {
223 $form_state['item']->temp_layout = $form_state['values']['layout'];
224 $form_state['clicked_button']['#next'] = 'move';
225 }
226 }
227 else {
228 $form_state['item']->display->layout = $form_state['values']['layout'];
b0d171fd
EM
229 }
230 }
231
232 /**
233 * When a layout is changed, the user is given the opportunity to move content.
234 */
235 function edit_form_move(&$form, &$form_state) {
236 $form_state['display'] = &$form_state['item']->display;
237 $form_state['layout'] = $form_state['item']->temp_layout;
238
239 ctools_include('common', 'panels');
240 ctools_include('display-layout', 'panels');
241 ctools_include('plugins', 'panels');
242
243 // Tell the Panels form not to display buttons.
244 $form_state['no buttons'] = TRUE;
245
246 // Change the #id of the form so the CSS applies properly.
247 $form = array_merge($form, panels_change_layout($form_state));
248
249 // This form is outside the normal wizard list, so we need to specify the
250 // previous/next forms.
251 $form['buttons']['previous']['#next'] = 'layout';
252 $form['buttons']['next']['#next'] = 'content';
253 }
254
255 function edit_form_move_submit(&$form, &$form_state) {
256 panels_change_layout_submit($form, $form_state);
257 }
258
259 function edit_form_content(&$form, &$form_state) {
260 ctools_include('ajax');
261 ctools_include('plugins', 'panels');
262 ctools_include('display-edit', 'panels');
263 ctools_include('context');
264
5f37de7e
EM
265 // If we are cloning an item, we MUST have this cached for this to work,
266 // so make sure:
267 if ($form_state['form type'] == 'clone' && empty($form_state['item']->export_ui_item_is_cached)) {
268 $this->edit_cache_set($form_state['item'], 'clone');
269 }
270
271 $cache = panels_edit_cache_get('panels_mini:' . $this->edit_cache_get_key($form_state['item'], $form_state['form type']));
b0d171fd
EM
272
273 $form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display);
274 $form_state['renderer']->cache = &$cache;
275
276 $form_state['display'] = &$cache->display;
277 $form_state['content_types'] = $cache->content_types;
278 // Tell the Panels form not to display buttons.
279 $form_state['no buttons'] = TRUE;
280 $form_state['display_title'] = !empty($cache->display_title);
281
282 $form = array_merge($form, panels_edit_display_form($form_state));
283 // Make sure the theme will work since our form id is different.
284 $form['#theme'] = 'panels_edit_display_form';
285 }
286
287 function edit_form_content_submit(&$form, &$form_state) {
288 panels_edit_display_form_submit($form, $form_state);
d22e5fdc 289 $form_state['item']->display = $form_state['display'];
b0d171fd 290 }
b0d171fd 291}