1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Contains common forms and routines that different object types use.
|
5
|
*
|
6
|
* The panelizer system has several different places that panels can be
|
7
|
* edited. While they are all subtly different, they have a lot in common.
|
8
|
*/
|
9
|
|
10
|
/**
|
11
|
* Form to configure basic panelizer settings.
|
12
|
*/
|
13
|
function panelizer_settings_form($form, &$form_state) {
|
14
|
$panelizer = $form_state['panelizer'];
|
15
|
|
16
|
if (!empty($form_state['has title'])) {
|
17
|
$form['title'] = array(
|
18
|
'#type' => 'textfield',
|
19
|
'#title' => t('Administrative title'),
|
20
|
'#description' => t('This will appear in the administrative interface to easily identify it.'),
|
21
|
'#default_value' => $panelizer->title,
|
22
|
);
|
23
|
}
|
24
|
|
25
|
// We only allow this setting on the "full page override" because it
|
26
|
// does not make sense in other modes.
|
27
|
if ($form_state['view_mode'] == 'page_manager') {
|
28
|
$form['no_blocks'] = array(
|
29
|
'#type' => 'checkbox',
|
30
|
'#default_value' => $panelizer->no_blocks,
|
31
|
'#title' => t('Disable Drupal blocks/regions'),
|
32
|
'#description' => t("Check this to have the display not show the theme's sidebars. Note that some themes support this setting better than others. If in doubt, try with stock themes to see."),
|
33
|
);
|
34
|
}
|
35
|
|
36
|
ctools_include('plugins', 'panels');
|
37
|
$pipelines = panels_get_renderer_pipelines();
|
38
|
|
39
|
// If there are no pipelines, that probably means we're operating in
|
40
|
// legacy mode.
|
41
|
if (empty($pipelines)) {
|
42
|
// We retain the original pipeline so we don't wreck things by installing
|
43
|
// old modules.
|
44
|
$form['pipeline'] = array(
|
45
|
'#type' => 'value',
|
46
|
'#value' => $panelizer->pipeline,
|
47
|
);
|
48
|
}
|
49
|
else {
|
50
|
$options = array();
|
51
|
foreach ($pipelines as $name => $pipeline) {
|
52
|
$options[$name] = check_plain($pipeline->admin_title) . '<div class="description">' . check_plain($pipeline->admin_description) . '</div>';
|
53
|
}
|
54
|
|
55
|
$form['pipeline'] = array(
|
56
|
'#type' => 'radios',
|
57
|
'#options' => $options,
|
58
|
'#title' => t('Renderer'),
|
59
|
'#default_value' => $panelizer->pipeline,
|
60
|
);
|
61
|
}
|
62
|
|
63
|
if ($form_state['view_mode'] != 'page_manager') {
|
64
|
$form['title_element'] = array(
|
65
|
'#type' => 'textfield',
|
66
|
'#default_value' => $panelizer->title_element,
|
67
|
'#title' => t('Title element'),
|
68
|
'#description' => t('The HTML element to use for the entity title. Typically this will be an H2.'),
|
69
|
);
|
70
|
|
71
|
$form['link_to_entity'] = array(
|
72
|
'#type' => 'checkbox',
|
73
|
'#default_value' => $panelizer->link_to_entity,
|
74
|
'#title' => t('Link title to entity'),
|
75
|
'#description' => t('If checked the title will be a link to the entity.'),
|
76
|
);
|
77
|
|
78
|
$form['css_class'] = array(
|
79
|
'#type' => 'textfield',
|
80
|
'#size' => 35,
|
81
|
'#default_value' => $panelizer->css_class,
|
82
|
'#title' => t('CSS class'),
|
83
|
'#description' => t('The CSS class to apply to this display. You may use context substitions here.'),
|
84
|
);
|
85
|
}
|
86
|
else {
|
87
|
$form['css_class'] = array(
|
88
|
'#type' => 'textfield',
|
89
|
'#size' => 35,
|
90
|
'#default_value' => $panelizer->css_class,
|
91
|
'#title' => t('Body class'),
|
92
|
'#description' => t('The CSS class to apply to the BODY tag. You may use context substitions here.'),
|
93
|
);
|
94
|
}
|
95
|
|
96
|
$form['css_id'] = array(
|
97
|
'#type' => 'textfield',
|
98
|
'#size' => 35,
|
99
|
'#default_value' => $panelizer->css_id,
|
100
|
'#title' => t('CSS ID'),
|
101
|
'#description' => t('The CSS ID to apply to this display.'),
|
102
|
);
|
103
|
|
104
|
$form['css'] = array(
|
105
|
'#type' => 'textarea',
|
106
|
'#title' => t('CSS code'),
|
107
|
'#description' => t('Enter well-formed CSS code here; this code will be embedded into the display and should only be used for minor adjustments; it is usually better to try to put CSS for this display into the theme if possible. This CSS will be filtered for safety so some CSS may not work.'),
|
108
|
'#default_value' => $panelizer->css,
|
109
|
);
|
110
|
|
111
|
panelizer_add_revision_info_form($form, $form_state);
|
112
|
|
113
|
$form['actions'] = array(
|
114
|
'#type' => 'actions',
|
115
|
);
|
116
|
|
117
|
$form['actions']['submit'] = array(
|
118
|
'#type' => 'submit',
|
119
|
'#value' => t('Save'),
|
120
|
);
|
121
|
|
122
|
return $form;
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* Submit callback
|
127
|
*/
|
128
|
function panelizer_settings_form_submit(&$form, &$form_state) {
|
129
|
$panelizer = $form_state['panelizer'];
|
130
|
if ($form_state['view_mode'] == 'page_manager') {
|
131
|
$panelizer->no_blocks = $form_state['values']['no_blocks'];
|
132
|
}
|
133
|
else {
|
134
|
$panelizer->title_element = $form_state['values']['title_element'];
|
135
|
}
|
136
|
|
137
|
$panelizer->css_class = $form_state['values']['css_class'];
|
138
|
$panelizer->css = $form_state['values']['css'];
|
139
|
$panelizer->css_id = $form_state['values']['css_id'];
|
140
|
$panelizer->pipeline = $form_state['values']['pipeline'];
|
141
|
// Behind an if because this value does not always exist.
|
142
|
if (isset($form_state['values']['link_to_entity'])) {
|
143
|
$panelizer->link_to_entity = $form_state['values']['link_to_entity'];
|
144
|
}
|
145
|
if (!empty($form_state['has title'])) {
|
146
|
$panelizer->title = $form_state['values']['title'];
|
147
|
}
|
148
|
// NOTE: We do not save in the submit so that the form can be re-used.
|
149
|
}
|
150
|
|
151
|
/**
|
152
|
* Mini form to add revision settings to a panelizer form so that
|
153
|
* we can properly handle revisioning.
|
154
|
*/
|
155
|
function panelizer_add_revision_info_form(&$form, &$form_state) {
|
156
|
if (empty($form_state['entity'])) {
|
157
|
return;
|
158
|
}
|
159
|
if (empty($form_state['revision info'])) {
|
160
|
return;
|
161
|
}
|
162
|
|
163
|
$entity = $form_state['entity'];
|
164
|
|
165
|
list($use_revisions, $control_revisions, $default_revision) = $form_state['revision info'];
|
166
|
|
167
|
if ($use_revisions) {
|
168
|
// @todo -- what if an entity uses some other flag to control revisioning?
|
169
|
if (!isset($entity->revision)) {
|
170
|
$entity->revision = $default_revision;
|
171
|
$entity->log = '';
|
172
|
}
|
173
|
|
174
|
$form_state['use revisions'] = TRUE;
|
175
|
$form['revision_information'] = array(
|
176
|
'#weight' => 11,
|
177
|
);
|
178
|
|
179
|
$form['revision_information']['revision'] = array(
|
180
|
'#type' => 'checkbox',
|
181
|
'#title' => t('Create new revision'),
|
182
|
'#default_value' => !empty($entity->revision),
|
183
|
'#id' => 'edit-revision',
|
184
|
'#access' => $control_revisions,
|
185
|
);
|
186
|
|
187
|
if ($control_revisions || $entity->revision) {
|
188
|
$form['revision_information']['log'] = array(
|
189
|
'#type' => 'textarea',
|
190
|
'#title' => t('Log message'),
|
191
|
'#description' => t('Provide an explanation of the changes you are making. This will help other authors understand your motivations.'),
|
192
|
'#default_value' => $entity->log,
|
193
|
);
|
194
|
|
195
|
if ($control_revisions) {
|
196
|
$form['revision_information']['log']['#dependency'] = array('edit-revision' => array(1));
|
197
|
}
|
198
|
}
|
199
|
|
200
|
// Don't override the existing submit, eh?
|
201
|
if (!empty($form_state['input']['form_id']) && empty($form['#submit']) && function_exists($form_state['input']['form_id'] . '_submit')) {
|
202
|
$form['#submit'][] = $form_state['input']['form_id'] . '_submit';
|
203
|
}
|
204
|
|
205
|
// The submit handler needs to go in a different location depending on
|
206
|
// what form this is.
|
207
|
$submit_handler = 'panelizer_add_revision_info_form_submit';
|
208
|
if (!empty($form['buttons']['submit']['#submit'])) {
|
209
|
$form['buttons']['submit']['#submit'][] = $submit_handler;
|
210
|
}
|
211
|
elseif (!empty($form['buttons']['return']['#submit'])) {
|
212
|
$form['buttons']['return']['#submit'][] = $submit_handler;
|
213
|
}
|
214
|
else {
|
215
|
$form['#submit'][] = $submit_handler;
|
216
|
}
|
217
|
}
|
218
|
}
|
219
|
|
220
|
/**
|
221
|
* Form submission callback for panelizer_add_revision_info_form().
|
222
|
*/
|
223
|
function panelizer_add_revision_info_form_submit(&$form, &$form_state) {
|
224
|
$entity = &$form_state['entity'];
|
225
|
if (!empty($form_state['use revisions'])) {
|
226
|
$entity->revision = $form_state['values']['revision'];
|
227
|
$entity->log = $form_state['values']['log'];
|
228
|
}
|
229
|
}
|
230
|
|
231
|
/**
|
232
|
* Form to edit contexts that go with a Panelizer display.
|
233
|
*/
|
234
|
function panelizer_default_context_form($form, &$form_state) {
|
235
|
ctools_include('context-admin');
|
236
|
ctools_context_admin_includes();
|
237
|
|
238
|
$panelizer = &$form_state['panelizer'];
|
239
|
|
240
|
if (!empty($panelizer->cached)) {
|
241
|
$form['markup'] = array(
|
242
|
'#prefix' => '<div class="messages warning">',
|
243
|
'#markup' => t('This form contains unsaved changes that will not be stored until the Save button is clicked.'),
|
244
|
'#suffix' => '</div>',
|
245
|
);
|
246
|
}
|
247
|
|
248
|
$form['right'] = array(
|
249
|
'#prefix' => '<div class="clear-block"><div class="right-container">',
|
250
|
'#suffix' => '</div>',
|
251
|
);
|
252
|
|
253
|
$form['left'] = array(
|
254
|
'#prefix' => '<div class="left-container">',
|
255
|
'#suffix' => '</div></div>',
|
256
|
);
|
257
|
|
258
|
$module = 'panelizer_context::' . $form_state['panelizer type'];
|
259
|
ctools_context_add_context_form($module, $form, $form_state, $form['right']['contexts_table'], $panelizer, $form_state['cache key']);
|
260
|
ctools_context_add_relationship_form($module, $form, $form_state, $form['right']['relationships_table'], $panelizer, $form_state['cache key']);
|
261
|
|
262
|
// Set an additional description if CCK and Token are enabled, to notify of unlisted keywords
|
263
|
if (!module_exists('token')) {
|
264
|
$description = t('More keywords will be available if you install the Token module, see http://drupal.org/project/token.');
|
265
|
}
|
266
|
else {
|
267
|
$description = '';
|
268
|
}
|
269
|
|
270
|
$form['left']['summary'] = array(
|
271
|
'#prefix' => '<div class="page-manager-contexts">',
|
272
|
'#suffix' => '</div>',
|
273
|
'#markup' => theme('ctools_context_list', array(
|
274
|
'object' => $panelizer,
|
275
|
'header' => t('Summary of contexts'),
|
276
|
'description' => $description,
|
277
|
)),
|
278
|
);
|
279
|
|
280
|
panelizer_add_revision_info_form($form, $form_state);
|
281
|
|
282
|
$form['actions'] = array(
|
283
|
'#type' => 'actions'
|
284
|
);
|
285
|
|
286
|
$form['actions']['submit'] = array(
|
287
|
'#type' => 'submit',
|
288
|
'#value' => t('Save'),
|
289
|
'#write' => TRUE,
|
290
|
);
|
291
|
|
292
|
$form['actions']['cancel'] = array(
|
293
|
'#type' => 'submit',
|
294
|
'#value' => t('Cancel'),
|
295
|
);
|
296
|
|
297
|
return $form;
|
298
|
}
|
299
|
|
300
|
/**
|
301
|
* Form used when an entity bundle is panelized but there is no default
|
302
|
* display. Entities are then individually panelized.
|
303
|
*/
|
304
|
function panelizer_panelize_entity_form($form, &$form_state) {
|
305
|
$entity_type = $form_state['panelizer']->panelizer_type;
|
306
|
$entity_info = entity_get_info($entity_type);
|
307
|
$form = array();
|
308
|
|
309
|
$form['markup'] = array(
|
310
|
'#markup' => '<p>' . t('This %entity is not currently panelized.', array('%entity' => $entity_info['label'])) . '</p>',
|
311
|
);
|
312
|
|
313
|
$form['submit'] = array(
|
314
|
'#type' => 'submit',
|
315
|
'#value' => t('Panelize it!'),
|
316
|
);
|
317
|
|
318
|
return $form;
|
319
|
}
|
320
|
|
321
|
/**
|
322
|
* Form used when an entity is panelized and is being reset.
|
323
|
*/
|
324
|
function panelizer_reset_entity_form($form, &$form_state) {
|
325
|
$entity_type = $form_state['panelizer']->entity_type;
|
326
|
$entity_info = entity_get_info($entity_type);
|
327
|
$form = array();
|
328
|
|
329
|
// Build the confirmation form.
|
330
|
$form = confirm_form(
|
331
|
$form,
|
332
|
t('Are you sure you want to reset the panelizer status for this %entity?', array('%entity' => $entity_info['label'])),
|
333
|
dirname(dirname($_GET['q'])),
|
334
|
t('This %entity will be reset to the default panelizer state, discarding any modifications made to it. This action cannot be undone.', array('%entity' => $entity_info['label'])),
|
335
|
t('Reset'),
|
336
|
t('Cancel'),
|
337
|
'panelizer_reset_entity_confirm');
|
338
|
|
339
|
// Append the revision form.
|
340
|
panelizer_add_revision_info_form($form, $form_state);
|
341
|
|
342
|
return $form;
|
343
|
}
|
344
|
|
345
|
/**
|
346
|
* Panelizer layout change form. If there is no content this will be
|
347
|
* a 'choose' layout form. If there is content it will be a 'change' layout
|
348
|
* form.
|
349
|
*
|
350
|
* @param $form_state
|
351
|
* The initial form state array to be used by the wizard. This *must* contain:
|
352
|
* - 'display': The display whose layout should be changed.
|
353
|
* - 'wizard path': The Drupal path where this wizard lives, so it knows where
|
354
|
* to redirect to. Note that the layout chosen will be appended to this
|
355
|
* path for the second step, so the page callback for this wizard needs to
|
356
|
* make sure to pass that through when teh function is called.
|
357
|
*
|
358
|
* This can also contain:
|
359
|
* - 'allowed_layouts' => The key to the allowed layouts array to use.
|
360
|
* - 'finish' => The text to use on the save button.
|
361
|
*
|
362
|
* @param $step
|
363
|
* The wizard step that must be passed through. It should be in the %step
|
364
|
* portion of the path.
|
365
|
*
|
366
|
* @param $layout
|
367
|
* A layout that is chosen in the first step. It is passed through the URL
|
368
|
* so that no caching is needed. The caller needs to be sure to extract this
|
369
|
* from the URL.
|
370
|
*
|
371
|
* @return
|
372
|
* While the return value is render array, if $form_state['complete'] is
|
373
|
* true, then$form_state['display'] can be saved by the caller and
|
374
|
* redirection chosen. If $form_state['cancel'] is true, then the display
|
375
|
* should not be saved.
|
376
|
*/
|
377
|
function panelizer_change_layout_wizard(&$form_state, $step = 'choose', $layout = NULL) {
|
378
|
ctools_include('common', 'panels');
|
379
|
|
380
|
// Add defaults to the form state sent in.
|
381
|
$form_state += array(
|
382
|
'finish' => t('Save'),
|
383
|
'allowed_layouts' => '',
|
384
|
'no_redirect' => TRUE,
|
385
|
'no buttons' => TRUE,
|
386
|
'layout' => $layout,
|
387
|
);
|
388
|
|
389
|
$form_info = array(
|
390
|
'id' => 'panelizer_change_layout_wizard',
|
391
|
'finish text' => $form_state['finish'],
|
392
|
'path' => $form_state['wizard path'],
|
393
|
'show back' => TRUE,
|
394
|
'order' => array(
|
395
|
'choose' => t('Choose layout'),
|
396
|
),
|
397
|
'forms' => array(
|
398
|
'choose' => array(
|
399
|
'form id' => 'panelizer_choose_layout_form',
|
400
|
),
|
401
|
'move' => array(
|
402
|
'form id' => 'panelizer_move_content_form',
|
403
|
),
|
404
|
),
|
405
|
);
|
406
|
|
407
|
if (!empty($form_state['display']->content)) {
|
408
|
$form_info['order']['move'] = t('Move content');
|
409
|
}
|
410
|
|
411
|
ctools_include('common', 'panels');
|
412
|
ctools_include('display-layout', 'panels');
|
413
|
ctools_include('plugins', 'panels');
|
414
|
ctools_include('wizard');
|
415
|
$output = ctools_wizard_multistep_form($form_info, $step, $form_state);
|
416
|
if (!empty($form_state['complete'])) {
|
417
|
$form_state['display']->layout = $form_state['layout'];
|
418
|
}
|
419
|
|
420
|
return $output;
|
421
|
}
|
422
|
|
423
|
function panelizer_choose_layout_form($form, &$form_state) {
|
424
|
// Change the #id of the form so the CSS applies properly.
|
425
|
$form['#id'] = 'panels-choose-layout';
|
426
|
$form = panels_choose_layout($form, $form_state);
|
427
|
|
428
|
if (!empty($form['buttons']['return'])) {
|
429
|
panelizer_add_revision_info_form($form, $form_state);
|
430
|
}
|
431
|
|
432
|
return $form;
|
433
|
}
|
434
|
|
435
|
function panelizer_choose_layout_form_validate(&$form, &$form_state) {
|
436
|
if ($form_state['values']['layout'] == $form_state['display']->layout) {
|
437
|
form_error($form['layout'], t('You must select a different layout if you wish to change layouts.'));
|
438
|
}
|
439
|
}
|
440
|
|
441
|
function panelizer_choose_layout_form_submit(&$form, &$form_state) {
|
442
|
$form_state['layout'] = $form_state['values']['layout'];
|
443
|
$form_state['form_info']['path'] .= '/' . $form_state['values']['layout'];
|
444
|
}
|
445
|
|
446
|
function panelizer_move_content_form($form, &$form_state) {
|
447
|
// Tell the Panels form not to display buttons.
|
448
|
$form_state['no buttons'] = TRUE;
|
449
|
|
450
|
// Change the #id of the form so the CSS applies properly.
|
451
|
$form = panels_change_layout($form, $form_state);
|
452
|
|
453
|
$form['buttons']['return']['#submit'][] = 'panels_change_layout_submit';
|
454
|
panelizer_add_revision_info_form($form, $form_state);
|
455
|
return $form;
|
456
|
}
|
457
|
|
458
|
function panelizer_edit_content_form($form, &$form_state) {
|
459
|
ctools_include('ajax');
|
460
|
ctools_include('plugins', 'panels');
|
461
|
ctools_include('display-edit', 'panels');
|
462
|
ctools_include('context');
|
463
|
|
464
|
$cache = $form_state['display cache'];
|
465
|
|
466
|
$form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display);
|
467
|
$form_state['renderer']->cache = $cache;
|
468
|
|
469
|
$form_state['display'] = &$cache->display;
|
470
|
$form_state['content_types'] = $cache->content_types;
|
471
|
$form_state['display_title'] = TRUE;
|
472
|
|
473
|
$form = panels_edit_display_form($form, $form_state);
|
474
|
|
475
|
panelizer_add_revision_info_form($form, $form_state);
|
476
|
$form['preview']['#weight'] = 100;
|
477
|
|
478
|
return $form;
|
479
|
}
|