Projet

Général

Profil

Paste
Télécharger (14,3 ko) Statistiques
| Branche: | Révision:

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

1
<?php
2
/**
3
 * @file
4
 * Contains administrative forms and settings.
5
 */
6

    
7
/**
8
 * Delegated hook_menu for admin
9
 *
10
 * Since most of hook_menu is delegated to plugins anyway, the admin menu
11
 * is delegated here to reduce code weight.
12
 */
13
function panelizer_admin_hook_menu(&$items) {
14
  // Configure settings pages.
15
  $settings_base = array(
16
    'access arguments' => array('administer panelizer'),
17
    'file' => 'includes/admin.inc',
18
  );
19

    
20
  $items['admin/config/content/panelizer'] = array(
21
    'title' => 'Panelizer',
22
    'description' => 'Configure panelizer availability and defaults',
23
    'page callback' => 'drupal_get_form',
24
    'page arguments' => array('panelizer_settings_page_form'),
25
    'type' => MENU_NORMAL_ITEM,
26
  ) + $settings_base;
27

    
28
  $items['admin/config/content/panelizer/%panelizer_handler/%/allowed'] = array(
29
    'title' => 'Allowed content',
30
    'page callback' => 'panelizer_allowed_content_page',
31
    'page arguments' => array(4, 5),
32
    'type' => MENU_CALLBACK,
33
    'weight' => -10,
34
  ) + $settings_base;
35

    
36
  $tabs_base = array(
37
    'access callback' => 'panelizer_has_no_choice_callback',
38
    'access arguments' => array(4, 5),
39
    'page arguments' => array(4, 5, 'default', ''),
40
    'type' => MENU_LOCAL_TASK,
41
    'file' => 'includes/admin.inc',
42
  );
43

    
44
  $items['admin/config/content/panelizer/%panelizer_handler/%'] = array(
45
    'title callback' => 'panelizer_default_title_callback',
46
    'title arguments' => array(4, 5),
47
    'title' => 'Settings',
48
    'page callback' => 'panelizer_default_settings_page',
49
    'weight' => -5,
50
    'type' => MENU_SUGGESTED_ITEM,
51
  ) + $tabs_base;
52

    
53
  $index = 0;
54
  foreach (panelizer_operations() as $path => $operation) {
55
    $items['admin/config/content/panelizer/%panelizer_handler/%/' . $path] = array(
56
      'title' => $operation['menu title'],
57
      'page callback' => $operation['admin callback'],
58
      'weight' => $index - 5,
59
      'type' => ($index === 0) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
60
    ) + $tabs_base;
61
    if (isset($operation['file'])) {
62
      $items['admin/config/content/panelizer/%panelizer_handler/%/' . $path]['file'] = $operation['file'];
63
    }
64
    if (isset($operation['file path'])) {
65
      $items['admin/config/content/panelizer/%panelizer_handler/%/' . $path]['file path'] = $operation['file path'];
66
    }
67
    $index++;
68
  }
69

    
70
  $subtabs_base = array(
71
    'access callback' => 'panelizer_administer_panelizer_default',
72
    'access arguments' => array(4, 5, 7),
73
    'page arguments' => array(4, 5, 7, ''),
74
    'type' => MENU_LOCAL_TASK,
75
    'file' => 'includes/admin.inc',
76
  );
77

    
78
  $items['admin/config/content/panelizer/%panelizer_handler/%/list/%'] = array(
79
    'title' => 'Settings',
80
    'page callback' => 'panelizer_default_settings_page',
81
    'title callback' => 'panelizer_default_name_title_callback',
82
    'type' => MENU_CALLBACK,
83
  ) + $subtabs_base;
84

    
85
  $index = 0;
86
  foreach (panelizer_operations() as $path => $operation) {
87
    $items['admin/config/content/panelizer/%panelizer_handler/%/list/%/' . $path] = array(
88
      'title' => $operation['menu title'],
89
      'page callback' => $operation['admin callback'],
90
      'weight' => $index - 5,
91
    ) + $subtabs_base;
92
    if (isset($operation['file'])) {
93
      $items['admin/config/content/panelizer/%panelizer_handler/%/list/%/' . $path]['file'] = $operation['file'];
94
    }
95
    if (isset($operation['file path'])) {
96
      $items['admin/config/content/panelizer/%panelizer_handler/%/list/%/' . $path]['file path'] = $operation['file path'];
97
    }
98
    $index++;
99
  }
100

    
101
  $items['admin/config/content/panelizer/%panelizer_handler/%/list/%/access'] = array(
102
    'title' => 'Access',
103
    'page callback' => 'panelizer_default_access_page',
104
    'weight' => -2,
105
  ) + $subtabs_base;
106

    
107
}
108

    
109
/**
110
 * Primary settings page.
111
 *
112
 * This settings page allows the administrator to select which node types
113
 * can be panelized, whether they have a default, and provides links to
114
 * edit those defaults.
115
 */
116
function panelizer_settings_page_form($form, &$form_state) {
117
  $form['entities'] = array('#tree' => TRUE);
118

    
119
  $plugins = panelizer_get_entity_plugins();
120
  foreach ($plugins as $entity_type => $plugin) {
121
    $entity_info = entity_get_info($entity_type);
122
    if ($entity_info) {
123
      if ($handler = panelizer_entity_plugin_get_handler($entity_type)) {
124
        $handler->settings_form($form, $form_state);
125
      }
126
    }
127
  }
128

    
129
  $form['submit'] = array(
130
    '#type' => 'submit',
131
    '#value' => t('Save'),
132
  );
133

    
134
  return $form;
135
}
136

    
137
/**
138
 * Format the output of the main settings form.
139
 *
140
 * We want our checkboxes to show up in a table.
141
 */
142
function theme_panelizer_settings_page_table($variables) {
143
  $element = $variables['element'];
144

    
145
  // Render the table
146
  $header = $element['#header'];
147
  $columns = $element['#columns'];
148

    
149
  $rows = array();
150
  foreach (element_children($element) as $bundle) {
151
    foreach (element_children($element[$bundle]) as $view_mode) {
152
      $row = array();
153
      foreach ($columns as $column) {
154
        $row[] = drupal_render($element[$bundle][$view_mode][$column]);
155
      }
156

    
157
      $rows[] = $row;
158
    }
159
  }
160

    
161
  $output = theme('table', array('header' => $header, 'rows' => $rows));
162

    
163
  // Render everything else
164
  $output .= drupal_render_children($element);
165
  return $output;
166
}
167

    
168
function panelizer_settings_page_form_validate($form, &$form_state) {
169
  $plugins = panelizer_get_entity_plugins();
170
  foreach ($plugins as $entity_type => $plugin) {
171
    $entity_info = entity_get_info($entity_type);
172
    if ($entity_info) {
173
      if ($handler = panelizer_entity_plugin_get_handler($entity_type)) {
174
        $handler->settings_form_validate($form, $form_state);
175
      }
176
    }
177
  }
178
}
179

    
180
function panelizer_settings_page_form_submit($form, &$form_state) {
181
  $plugins = panelizer_get_entity_plugins();
182
  foreach ($plugins as $entity_type => $plugin) {
183
    $entity_info = entity_get_info($entity_type);
184
    if ($entity_info) {
185
      if ($handler = panelizer_entity_plugin_get_handler($entity_type)) {
186
        $handler->settings_form_submit($form, $form_state);
187
      }
188
    }
189
  }
190

    
191
  // Ensure that defaults get cached to recognize new settings immediately.
192
  drupal_flush_all_caches();
193
}
194

    
195
/**
196
 * Page to configure what content is available for a given node type.
197
 */
198
function panelizer_allowed_content_page($handler, $bundle) {
199
  // Old URLs would include a view mode, but allowed content does not
200
  // change for view modes, so make that version of the page not found.
201
  if (strpos($bundle, '.') !== FALSE) {
202
    return MENU_NOT_FOUND;
203
  }
204

    
205
  if (is_string($handler)) {
206
    $handler = panelizer_entity_plugin_get_handler($handler);
207
  }
208

    
209
  if (!$handler->is_panelized($bundle)) {
210
    return MENU_NOT_FOUND;
211
  }
212

    
213
  ctools_include('common', 'panels');
214
  return drupal_get_form('panels_common_settings', 'panelizer_' . $handler->entity_type . ':' . $bundle);
215
}
216

    
217
/**
218
 * Page to configure basic settings for a panelizer default.
219
 */
220
function panelizer_default_settings_page($handler, $bundle, $name, $view_mode) {
221
  if (is_string($handler)) {
222
    $handler = panelizer_entity_plugin_get_handler($handler);
223
  }
224

    
225
  if ($view_mode) {
226
    $bundle .= '.' . $view_mode;
227
    // We use a $mode copy of $view_mode because the presence of $view_mode
228
    // tells us later if we want fake tabs, but we still need to know the
229
    // actual view mode regardless of that.
230
    $mode = $view_mode;
231
  }
232
  else {
233
    // We are NOT testing for the . here because if this is missing
234
    // that is a sign of a bug and we want the notice.
235
    list(, $mode) = explode('.', $bundle);
236
  }
237

    
238
  $panelizer = $handler->get_default_panelizer_object($bundle, $name);
239
  if (empty($panelizer)) {
240
    return MENU_NOT_FOUND;
241
  }
242

    
243
  $form_state = array(
244
    'panelizer' => &$panelizer,
245
    'no_redirect' => TRUE,
246
    'view_mode' => $mode,
247
  );
248

    
249
  if ($handler->has_panel_choice($bundle)) {
250
    $form_state['has title'] = TRUE;
251
  }
252

    
253
  ctools_include('common', 'panelizer');
254
  $output = drupal_build_form('panelizer_settings_form', $form_state);
255
  if (!empty($form_state['executed'])) {
256
    ctools_include('export');
257
    ctools_export_crud_save('panelizer_defaults', $panelizer);
258
    drupal_set_message(t('The settings have been updated.'));
259
    drupal_goto($_GET['q']);
260
  }
261

    
262
  if ($view_mode && !$handler->has_panel_choice($bundle)) {
263
    $output = $handler->wrap_default_panelizer_pages($bundle, $output);
264
  }
265

    
266
  return $output;
267
}
268

    
269
/**
270
 * Delete a panelizer node panel from the database.
271
 */
272
function panelizer_delete_panelizer_defaults($panelizer) {
273
  if (!empty($panelizer->pnid)) {
274
    if (!empty($panelizer->did)) {
275
      panels_delete_display($panelizer->did);
276
    }
277
    db_delete('panelizer_defaults')
278
      ->condition('pnid', $panelizer->pnid)
279
      ->execute();
280
  }
281
}
282

    
283
/**
284
 * Page to configure what content is available for a given node type.
285
 */
286
function panelizer_default_context_page($handler, $bundle, $name, $view_mode) {
287
  if (is_string($handler)) {
288
    $handler = panelizer_entity_plugin_get_handler($handler);
289
  }
290

    
291
  if ($view_mode) {
292
    $bundle .= '.' . $view_mode;
293
  }
294

    
295
  $cache_key = $handler->entity_type . ':' . $bundle . ':' . $name;
296
  $panelizer = panelizer_context_cache_get('default', $cache_key);
297
  if (empty($panelizer)) {
298
    return MENU_NOT_FOUND;
299
  }
300

    
301
  $form_state = array(
302
    'panelizer' => &$panelizer,
303
    'panelizer type' => 'default',
304
    'cache key' => $cache_key,
305
    'no_redirect' => TRUE,
306
  );
307

    
308
  ctools_include('common', 'panelizer');
309
  $output = drupal_build_form('panelizer_default_context_form', $form_state);
310
  if (!empty($form_state['executed'])) {
311
    if (!empty($form_state['clicked_button']['#write'])) {
312
      drupal_set_message(t('The settings have been updated.'));
313
      ctools_include('export');
314
      ctools_export_crud_save('panelizer_defaults', $panelizer);
315
    }
316
    else {
317
      drupal_set_message(t('Changes have been discarded.'));
318
    }
319

    
320
    panelizer_context_cache_clear('default', $cache_key);
321
    drupal_goto($_GET['q']);
322
  }
323

    
324
  if ($view_mode && !$handler->has_panel_choice($bundle)) {
325
    $output = $handler->wrap_default_panelizer_pages($bundle, $output);
326
  }
327

    
328
  return $output;
329
}
330

    
331
/**
332
 * Pass through to the panels layout editor.
333
 */
334
function panelizer_default_layout_page($handler, $bundle, $name, $view_mode, $step = NULL, $layout = NULL) {
335
  if (is_string($handler)) {
336
    $handler = panelizer_entity_plugin_get_handler($handler);
337
  }
338

    
339
  if ($view_mode) {
340
    $bundle .= '.' . $view_mode;
341
  }
342

    
343
  $panelizer = $handler->get_default_panelizer_object($bundle, $name);
344
  if (empty($panelizer)) {
345
    return MENU_NOT_FOUND;
346
  }
347

    
348
  $display = $panelizer->display;
349
  $display->context = $handler->get_contexts($panelizer);
350

    
351
  if ($name == 'default' && $handler->has_default_panel($bundle)) {
352
    $path = 'admin/config/content/panelizer/' . $handler->entity_type . '/' . $bundle;
353
  }
354
  else {
355
    $path = 'admin/config/content/panelizer/' . $handler->entity_type . '/' . $bundle . '/list/' . $name ;
356
  }
357

    
358
  $form_state = array(
359
    'display' => $display,
360
    'wizard path' => $path . '/layout/%step',
361
    'allowed_layouts' => 'panelizer_' . $handler->entity_type . ':' . $bundle,
362
  );
363

    
364
  ctools_include('common', 'panelizer');
365
  $output = panelizer_change_layout_wizard($form_state, $step, $layout);
366
  if (!empty($form_state['complete'])) {
367
    $panelizer->display = $form_state['display'];
368
    ctools_export_crud_save('panelizer_defaults', $panelizer);
369
    drupal_set_message(t('The layout has been changed.'));
370
    drupal_goto($path . '/content');
371
  }
372

    
373
  if ($view_mode && !$handler->has_panel_choice($bundle)) {
374
    $output = $handler->wrap_default_panelizer_pages($bundle, $output);
375
  }
376

    
377
  return $output;
378
}
379

    
380
/**
381
 * Determine edit access for this panelizer default.
382
 */
383
function panelizer_default_access_page($handler, $bundle, $name, $view_mode) {
384
  if (is_string($handler)) {
385
    $handler = panelizer_entity_plugin_get_handler($handler);
386
  }
387

    
388
  if ($view_mode) {
389
    $bundle .= '.' . $view_mode;
390
  }
391

    
392
  $panelizer = $handler->get_default_panelizer_object($bundle, $name);
393
  if (empty($panelizer)) {
394
    return MENU_NOT_FOUND;
395
  }
396

    
397
  $argument = $name;
398

    
399
  ctools_include('context-access-admin');
400
  ctools_include('object-cache');
401

    
402
  // Ensure that if they visit this page fresh, any cached data is removed:
403
  if (empty($_POST)) {
404
    ctools_object_cache_clear('panelizer_access', $argument);
405
  }
406
  else {
407
    $access = ctools_object_cache_get('panelizer_access', $argument);
408
  }
409

    
410
  if (empty($access)) {
411
    $access = $panelizer->access;
412
  }
413

    
414
  if (!is_array($access)) {
415
    $access = array();
416
  }
417

    
418
  $form_state = array(
419
    'access' => $access,
420
    'module' => 'panelizer',
421
    'callback argument' => $argument,
422
    // A bug in context-access-admin requires this until it's fixed.
423
    'argument' => $argument,
424
    'contexts' => $handler->get_contexts($panelizer),
425
    'no_redirect' => TRUE,
426
  );
427

    
428
  $output = drupal_build_form('ctools_access_admin_form', $form_state);
429

    
430
  if (!empty($form_state['executed'])) {
431
    ctools_object_cache_clear('panelizer_access', $argument);
432
    $panelizer->access = $form_state['access'];
433
    ctools_export_crud_save('panelizer_defaults', $panelizer);
434

    
435
    drupal_set_message(t('The access settings have been updated.'));
436
    drupal_goto($_GET['q']);
437
  }
438

    
439
  return $output;
440
}
441

    
442
/**
443
 * Pass through to the panels content editor.
444
 */
445
function panelizer_default_content_page($handler, $bundle, $name, $view_mode) {
446
  if (is_string($handler)) {
447
    $handler = panelizer_entity_plugin_get_handler($handler);
448
  }
449

    
450
  if ($view_mode) {
451
    $bundle .= '.' . $view_mode;
452
  }
453

    
454
  $panelizer = $handler->get_default_panelizer_object($bundle, $name);
455
  if (empty($panelizer)) {
456
    return MENU_NOT_FOUND;
457
  }
458

    
459
  $cache_key = 'panelizer:default:' . $handler->entity_type . ':' . $bundle . ':' . $name;
460

    
461
  $form_state = array(
462
    'display cache' => panels_edit_cache_get($cache_key),
463
    'no_redirect' => TRUE,
464
  );
465

    
466
  ctools_include('common', 'panelizer');
467
  $output = drupal_build_form('panelizer_edit_content_form', $form_state);
468
  if (!empty($form_state['executed'])) {
469
    if (!empty($form_state['clicked_button']['#save-display'])) {
470
      drupal_set_message(t('The settings have been updated.'));
471
      $panelizer->display = $form_state['display'];
472
      ctools_export_crud_save('panelizer_defaults', $panelizer);
473
    }
474
    else {
475
      drupal_set_message(t('Changes have been discarded.'));
476
    }
477

    
478
    panels_edit_cache_clear($form_state['display cache']);
479
    drupal_goto($_GET['q']);
480
  }
481

    
482
  ctools_set_no_blocks(FALSE);
483

    
484
  if ($view_mode && !$handler->has_panel_choice($bundle)) {
485
    $output = $handler->wrap_default_panelizer_pages($bundle, $output);
486
  }
487

    
488
  drupal_set_page_content($output);
489
  $page = element_info('page');
490

    
491
  return $page;
492
}