Projet

Général

Profil

Paste
Télécharger (15,1 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / panelizer / includes / common.inc @ a5572547

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 panel disable sidebars displayed in the theme. 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 panel. 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 panel.'),
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 panel, and should only be used for minor adjustments; it is usually better to try to put CSS for the panel 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) = $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 = $use_revisions;
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
function panelizer_add_revision_info_form_submit(&$form, &$form_state) {
221
  $entity = $form_state['entity'];
222
  if (!empty($form_state['use revisions'])) {
223
    $entity->revision = $form_state['values']['revision'];
224
    $entity->log = $form_state['values']['log'];
225
  }
226
}
227

    
228
/**
229
 * Form to edit contexts that go with a panelizer panel.
230
 */
231
function panelizer_default_context_form($form, &$form_state) {
232
  ctools_include('context-admin');
233
  ctools_context_admin_includes();
234

    
235
  $panelizer = &$form_state['panelizer'];
236

    
237
  if (!empty($panelizer->cached)) {
238
    $form['markup'] = array(
239
      '#prefix' => '<div class="messages warning">',
240
      '#markup' => t('This form contains unsaved changes that will not be stored until the Save button is clicked.'),
241
      '#suffix' => '</div>',
242
    );
243
  }
244

    
245
  $form['right'] = array(
246
    '#prefix' => '<div class="clear-block"><div class="right-container">',
247
    '#suffix' => '</div>',
248
  );
249

    
250
  $form['left'] = array(
251
    '#prefix' => '<div class="left-container">',
252
    '#suffix' => '</div></div>',
253
  );
254

    
255
  $module = 'panelizer_context::' . $form_state['panelizer type'];
256
  ctools_context_add_context_form($module, $form, $form_state, $form['right']['contexts_table'], $panelizer, $form_state['cache key']);
257
  ctools_context_add_relationship_form($module, $form, $form_state, $form['right']['relationships_table'], $panelizer, $form_state['cache key']);
258

    
259
  // Set an additional description if CCK and Token are enabled, to notify of unlisted keywords
260
  if (!module_exists('token')) {
261
    $description = t('More keywords will be available if you install the Token module, see http://drupal.org/project/token.');
262
  }
263
  else {
264
    $description = '';
265
  }
266

    
267
  $form['left']['summary'] = array(
268
    '#prefix' => '<div class="page-manager-contexts">',
269
    '#suffix' => '</div>',
270
    '#markup' => theme('ctools_context_list', array(
271
      'object' => $panelizer,
272
      'header' => t('Summary of contexts'),
273
      'description' => $description,
274
    )),
275
  );
276

    
277
  panelizer_add_revision_info_form($form, $form_state);
278

    
279
  $form['actions'] = array(
280
    '#type' => 'actions'
281
  );
282

    
283
  $form['actions']['submit'] = array(
284
    '#type' => 'submit',
285
    '#value' => t('Save'),
286
    '#write' => TRUE,
287
  );
288

    
289
  $form['actions']['cancel'] = array(
290
    '#type' => 'submit',
291
    '#value' => t('Cancel'),
292
  );
293

    
294
  return $form;
295
}
296

    
297
/**
298
 * Form used when an entity bundle is panelized but there is no default
299
 * panel. Entities are then individually panelized.
300
 */
301
function panelizer_panelize_entity_form($form, &$form_state) {
302
  $entity_type = $form_state['panelizer']->panelizer_type;
303
  $entity_info = entity_get_info($entity_type);
304
  $form = array();
305

    
306
  $form['markup'] = array(
307
    '#markup' => '<p>' . t('This %entity is not currently panelized.', array('%entity' => $entity_info['label'])) . '</p>',
308
  );
309

    
310
  $form['submit'] = array(
311
    '#type' => 'submit',
312
    '#value' => t('Panelize it!'),
313
  );
314

    
315
  return $form;
316
}
317

    
318
/**
319
 * Form used when an entity is panelized and is being reset.
320
 */
321
function panelizer_reset_entity_form($form, &$form_state) {
322
  $entity_type = $form_state['panelizer']->entity_type;
323
  $entity_info = entity_get_info($entity_type);
324
  $form = array();
325

    
326
  return confirm_form(
327
    $form,
328
    t('Are you sure you want to reset the panelizer status for this %entity?', array('%entity' => $entity_info['label'])),
329
    dirname(dirname($_GET['q'])),
330
    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'])),
331
    t('Reset'),
332
    t('Cancel'),
333
    'panelizer_reset_entity_confirm');
334
}
335

    
336
/**
337
 * Panelizer layout change form. If there is no content this will be
338
 * a 'choose' layout form. If there is content it will be a 'change' layout
339
 * form.
340
 *
341
 * @param $form_state
342
 *   The initial form state array to be used by the wizard. This *must* contain:
343
 *   - 'display': The display whose layout should be changed.
344
 *   - 'wizard path': The Drupal path where this wizard lives, so it knows where
345
 *     to redirect to. Note that the layout chosen will be appended to this
346
 *     path for the second step, so the page callback for this wizard needs to
347
 *     make sure to pass that through when teh function is called.
348
 *
349
 *   This can also contain:
350
 *   - 'allowed_layouts' => The key to the allowed layouts array to use.
351
 *   - 'finish' => The text to use on the save button.
352
 *
353
 * @param $step
354
 *   The wizard step that must be passed through. It should be in the %step
355
 *   portion of the path.
356
 *
357
 * @param $layout
358
 *   A layout that is chosen in the first step. It is passed through the URL
359
 *   so that no caching is needed. The caller needs to be sure to extract this
360
 *   from the URL.
361
 *
362
 * @return
363
 *   While the return value is render array, if $form_state['complete'] is
364
 *   true, then$form_state['display'] can be saved by the caller and
365
 *   redirection chosen. If $form_state['cancel'] is true, then the display
366
 *   should not be saved.
367
 */
368
function panelizer_change_layout_wizard(&$form_state, $step = 'choose', $layout = NULL) {
369
  ctools_include('common', 'panels');
370

    
371
  // Add defaults to the form state sent in.
372
  $form_state += array(
373
    'finish' => t('Save'),
374
    'allowed_layouts' => '',
375
    'no_redirect' => TRUE,
376
    'no buttons' => TRUE,
377
    'layout' => $layout,
378
  );
379

    
380
  $form_info = array(
381
    'id' => 'panelizer_change_layout_wizard',
382
    'finish text' => $form_state['finish'],
383
    'path' => $form_state['wizard path'],
384
    'show back' => TRUE,
385
    'order' => array(
386
      'choose' => t('Choose layout'),
387
    ),
388
    'forms' => array(
389
      'choose' => array(
390
        'form id' => 'panelizer_choose_layout_form',
391
      ),
392
      'move' => array(
393
        'form id' => 'panelizer_move_content_form',
394
      ),
395
    ),
396
  );
397

    
398
  if (!empty($form_state['display']->content)) {
399
    $form_info['order']['move'] = t('Move content');
400
  }
401

    
402
  ctools_include('common', 'panels');
403
  ctools_include('display-layout', 'panels');
404
  ctools_include('plugins', 'panels');
405
  ctools_include('wizard');
406
  $output = ctools_wizard_multistep_form($form_info, $step, $form_state);
407
  if (!empty($form_state['complete'])) {
408
    $form_state['display']->layout = $form_state['layout'];
409
  }
410

    
411
  return $output;
412
}
413

    
414
function panelizer_choose_layout_form($form, &$form_state) {
415
  // Change the #id of the form so the CSS applies properly.
416
  $form['#id'] = 'panels-choose-layout';
417
  $form = panels_choose_layout($form, $form_state);
418

    
419
  if (!empty($form['buttons']['return'])) {
420
    panelizer_add_revision_info_form($form, $form_state);
421
  }
422

    
423
  return $form;
424
}
425

    
426
function panelizer_choose_layout_form_validate(&$form, &$form_state) {
427
  if ($form_state['values']['layout'] == $form_state['display']->layout) {
428
    form_error($form['layout'], t('You must select a different layout if you wish to change layouts.'));
429
  }
430
}
431

    
432
function panelizer_choose_layout_form_submit(&$form, &$form_state) {
433
  $form_state['layout'] = $form_state['values']['layout'];
434
  $form_state['form_info']['path'] .= '/' . $form_state['values']['layout'];
435
}
436

    
437
function panelizer_move_content_form($form, &$form_state) {
438
  // Tell the Panels form not to display buttons.
439
  $form_state['no buttons'] = TRUE;
440

    
441
  // Change the #id of the form so the CSS applies properly.
442
  $form = panels_change_layout($form, $form_state);
443

    
444
  $form['buttons']['return']['#submit'][] = 'panels_change_layout_submit';
445
  panelizer_add_revision_info_form($form, $form_state);
446
  return $form;
447
}
448

    
449
function panelizer_edit_content_form($form, &$form_state) {
450
  ctools_include('ajax');
451
  ctools_include('plugins', 'panels');
452
  ctools_include('display-edit', 'panels');
453
  ctools_include('context');
454

    
455
  $cache = $form_state['display cache'];
456

    
457
  $form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display);
458
  $form_state['renderer']->cache = $cache;
459

    
460
  $form_state['display'] = &$cache->display;
461
  $form_state['content_types'] = $cache->content_types;
462
  $form_state['display_title'] = TRUE;
463

    
464
  $form = panels_edit_display_form($form, $form_state);
465

    
466
  panelizer_add_revision_info_form($form, $form_state);
467
  $form['preview']['#weight'] = 100;
468

    
469
  return $form;
470
}