Project

General

Profile

Paste
Download (17.6 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / ds / includes / ds.registry.inc @ 6e9292aa

1
<?php
2

    
3
/**
4
 * @file
5
 * Registry file for Display Suite.
6
 */
7

    
8
/**
9
 * Implements hook_menu().
10
 */
11
function _ds_menu() {
12
  $items = array();
13

    
14
  // Layout overview.
15
  $items['admin/structure/ds'] = array(
16
    'title' => 'Display Suite',
17
    'description' => 'Manage layouts for entities and configure fields, view modes etc.',
18
    'page callback' => 'ds_layout_list',
19
    'file' => 'includes/ds.displays.inc',
20
    'access arguments' => array('admin_display_suite'),
21
  );
22

    
23
  // Layout overview, primary tab.
24
  $items['admin/structure/ds/list'] = array(
25
    'title' => 'Displays',
26
    'weight' => -10,
27
    'type' => MENU_DEFAULT_LOCAL_TASK,
28
  );
29

    
30
  // Layout overview, secondary tab.
31
  $items['admin/structure/ds/list/list'] = array(
32
    'title' => 'List',
33
    'weight' => -10,
34
    'type' => MENU_DEFAULT_LOCAL_TASK,
35
  );
36

    
37
  // Emergency page
38
  $items['admin/structure/ds/list/emergency'] = array(
39
    'title' => 'Emergency',
40
    'description' => 'In case you have errors via Display Suite, visit this page.',
41
    'page callback' => 'drupal_get_form',
42
    'page arguments' => array('ds_emergency'),
43
    'access arguments' => array('admin_display_suite'),
44
    'file' => 'includes/ds.displays.inc',
45
    'type' => MENU_LOCAL_TASK,
46
    'weight' => 100,
47
  );
48

    
49
  // Change layout.
50
  $items['admin/structure/ds/change-layout'] = array(
51
    'title' => 'Change layout',
52
    'description' => 'Act on layout change to move fields elsewhere',
53
    'page callback' => 'drupal_get_form',
54
    'page arguments' => array('ds_field_ui_layout_change'),
55
    'access arguments' => array('admin_display_suite'),
56
    'file' => 'includes/ds.field_ui.inc',
57
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
58
  );
59

    
60
  // Revert layout.
61
  $items['admin/structure/ds/revert-layout'] = array(
62
    'title' => 'Revert layout',
63
    'description' => 'Revert layout and field settings.',
64
    'page callback' => 'drupal_get_form',
65
    'page arguments' => array('ds_revert_layout_field_settings_form'),
66
    'file' => 'includes/ds.field_ui.inc',
67
    'access arguments' => array('admin_display_suite'),
68
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
69
  );
70

    
71
  // Disable layout.
72
  $items['admin/structure/ds/disable'] = array(
73
    'title' => 'Disable layout',
74
    'description' => 'Disable layout and field settings',
75
    'page callback' => 'drupal_get_form',
76
    'page arguments' => array('ds_disable_layout_field_settings_form'),
77
    'file' => 'includes/ds.field_ui.inc',
78
    'access arguments' => array('admin_display_suite'),
79
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
80
  );
81

    
82
  // Enable layout.
83
  $items['admin/structure/ds/enable'] = array(
84
    'title' => 'Enable layout',
85
    'description' => 'Enable layout and field settings',
86
    'page callback' => 'drupal_get_form',
87
    'page arguments' => array('ds_enable_layout_field_settings_form'),
88
    'file' => 'includes/ds.field_ui.inc',
89
    'access arguments' => array('admin_display_suite'),
90
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
91
  );
92

    
93
  // CTools content.
94
  $items['admin/structure/ds/fields/manage_ctools/content'] = array(
95
    'title' => 'Ctools field content',
96
    'page callback' => 'ds_ctools_content',
97
    'file' => 'includes/ds.field_ui.inc',
98
    'access arguments' => array('admin_display_suite'),
99
    'type' => MENU_CALLBACK,
100
  );
101

    
102
  // Contextual links.
103
  if (module_exists('contextual') && module_exists('field_ui')) {
104
    $items['node/%node/display'] = array(
105
      'title' => 'Manage display',
106
      'description' => 'Manage display of this content.',
107
      'page callback' => 'ds_contextual_page_tab',
108
      'page arguments' => array(1, 'node'),
109
      'file' => 'includes/ds.contextual.inc',
110
      'access arguments' => array('administer content types'),
111
      'type' => MENU_LOCAL_TASK,
112
    );
113

    
114
    $items['user/%user/display'] = array(
115
      'title' => 'Manage display',
116
      'description' => 'Manage display of this user profile.',
117
      'page callback' => 'ds_contextual_page_tab',
118
      'page arguments' => array(1, 'user'),
119
      'file' => 'includes/ds.contextual.inc',
120
      'access arguments' => array('administer users'),
121
      'type' => MENU_LOCAL_TASK,
122
    );
123

    
124
    if (module_exists('taxonomy')) {
125
      $items['taxonomy/term/%taxonomy_term/display'] = array(
126
        'title' => 'Manage display',
127
        'description' => 'Manage display of this term.',
128
        'page callback' => 'ds_contextual_page_tab',
129
        'page arguments' => array(2, 'taxonomy_term'),
130
        'access arguments' => array('administer taxonomy'),
131
        'type' => MENU_LOCAL_TASK,
132
        'weight' => 11,
133
        'file' => 'includes/ds.contextual.inc',
134
      );
135
    }
136
  }
137

    
138
  return $items;
139
}
140

    
141
/**
142
 * Implements hook_theme().
143
 */
144
function _ds_theme() {
145
  $theme_functions = array();
146

    
147
  // Layouts
148
  $layouts = ds_get_layout_info();
149
  foreach ($layouts as $key => $layout) {
150

    
151
    // We don't need panel layouts to be registered.
152
    if (isset($layout['module']) && $layout['module'] == 'panels') {
153
      continue;
154
    }
155

    
156
    $theme_functions[$key] = array(
157
      'render element' => 'elements',
158
      'template' => strtr($key, '_', '-'),
159
      'path' => $layout['path'],
160
    );
161
  }
162

    
163
  // Field templates
164
  $field_functions = module_invoke_all('ds_field_theme_functions_info');
165
  foreach ($field_functions as $key => $label) {
166
    $theme_functions[$key] = array(
167
      'render element' => 'element',
168
      'function' => $key,
169
    );
170
  }
171

    
172
  return $theme_functions;
173
}
174

    
175
/**
176
 * Implements hook_features_api().
177
 */
178
function _ds_features_api() {
179
  static $api = FALSE;
180

    
181
  if (!$api) {
182
    module_load_include('inc', 'features', 'includes/features.ctools');
183
    $api = ctools_component_features_api('ds');
184
    foreach ($api as $key => $value) {
185
      switch ($key) {
186
        case 'ds_field_settings':
187
          $api[$key]['name'] = 'Display Suite field settings';
188
          break;
189
        case 'ds_layout_settings':
190
          $api[$key]['name'] = 'Display Suite layout settings';
191
          break;
192
        case 'ds_view_modes':
193
          $api[$key]['name'] = 'Display Suite view modes';
194
          break;
195
        case 'ds_fields':
196
          $api[$key]['name'] = 'Display Suite fields';
197
          break;
198
      }
199
    }
200
  }
201

    
202
  return $api;
203
}
204

    
205
/**
206
 * Remove or rename layout & field settings on entity machine name update.
207
 *
208
 * @param $entity_type
209
 *   The name of the entity type.
210
 * @param $info
211
 *   The entity info.
212
 * @param $action
213
 *   The action, either update or delete.
214
 */
215
function _ds_entity_type_update($entity_type, $info, $action) {
216

    
217
  // Delete settings.
218
  if ($action == 'delete') {
219
    db_delete('ds_layout_settings')
220
      ->condition('entity_type', $entity_type)
221
      ->condition('bundle', $info->type)
222
      ->execute();
223
    db_delete('ds_field_settings')
224
      ->condition('entity_type', $entity_type)
225
      ->condition('bundle', $info->type)
226
      ->execute();
227
  }
228

    
229
  // Update settings.
230
  if ($action == 'update') {
231
    $records = db_query('SELECT * FROM {ds_layout_settings} WHERE entity_type = :entity_type AND bundle = :bundle', array(':entity_type' => $entity_type, ':bundle' => $info->old_type));
232
    foreach ($records as $record) {
233
      $old_id = $entity_type . '|' . $info->old_type . '|' . $record->view_mode;
234
      $new_id = $entity_type . '|' . $info->type . '|' . $record->view_mode;
235
      db_update('ds_layout_settings')
236
        ->fields(array(
237
          'id' => $new_id,
238
          'bundle' => $info->type)
239
        )
240
        ->condition('id', $old_id)
241
        ->execute();
242
    }
243
    $records = db_query('SELECT * FROM {ds_field_settings} WHERE entity_type = :entity_type AND bundle = :bundle', array(':entity_type' => $entity_type, ':bundle' => $info->old_type));
244
    foreach ($records as $record) {
245
      $old_id = $entity_type . '|' . $info->old_type . '|' . $record->view_mode;
246
      $new_id = $entity_type . '|' . $info->type . '|' . $record->view_mode;
247
      db_update('ds_field_settings')
248
        ->fields(array(
249
          'id' => $new_id,
250
          'bundle' => $info->type)
251
        )
252
        ->condition('id', $old_id)
253
        ->execute();
254
    }
255
  }
256

    
257
  // Clear cache.
258
  cache_clear_all('ds_fields:', 'cache', TRUE);
259
  cache_clear_all('ds_field_settings', 'cache');
260
  field_info_cache_clear();
261
}
262

    
263
/**
264
 * Implements hook_theme_registry_alter().
265
 */
266
function _ds_theme_registry_alter(&$theme_registry) {
267

    
268
  // Inject ds_entity_variables in all entity theming functions.
269
  $entity_info = entity_get_info();
270
  foreach ($entity_info as $entity => $info) {
271
    if (isset($entity_info[$entity]['fieldable']) && $entity_info[$entity]['fieldable']) {
272

    
273
      // User uses user_profile for theming.
274
      if ($entity == 'user') $entity = 'user_profile';
275

    
276
      // Only add preprocess functions if entity exposes theme function.
277
      if (isset($theme_registry[$entity])) {
278
        $theme_registry[$entity]['preprocess functions'][] = 'ds_entity_variables';
279
      }
280
    }
281
  }
282

    
283
  // Support for File Entity.
284
  if (isset($theme_registry['file_entity'])) {
285
    $theme_registry['file_entity']['preprocess functions'][] = 'ds_entity_variables';
286
  }
287

    
288
  // Support for Entity API.
289
  if (isset($theme_registry['entity'])) {
290
    $theme_registry['entity']['preprocess functions'][] = 'ds_entity_variables';
291
  }
292
}
293

    
294
/**
295
 * Implements hook_entity_info_alter().
296
 */
297
function _ds_entity_info_alter(&$entity_info) {
298

    
299
  // Make sure ds_view_modes table exists.
300
  if (!db_table_exists('ds_view_modes')) {
301
    return;
302
  }
303

    
304
  ctools_include('export');
305

    
306
  // Add custom view modes to entities.
307
  $custom_view_modes = ctools_export_crud_load_all('ds_view_modes');
308
  foreach ($custom_view_modes as $view_mode_key => $view_mode_value) {
309
    $view_mode = array(
310
      'label' => check_plain($view_mode_value->label),
311
      'custom settings' => FALSE,
312
    );
313
    foreach ($view_mode_value->entities as $entity_type) {
314
      if (isset($entity_info[$entity_type])) {
315
        $entity_info[$entity_type]['view modes'][$view_mode_key] = $view_mode;
316
      }
317
    }
318
  }
319

    
320
  // Add layout if applicable.
321
  $ds_layouts = ds_get_layout_info();
322
  $ds_layout_settings = ctools_export_crud_load_all('ds_layout_settings');
323
  foreach ($ds_layout_settings as $row) {
324

    
325
    // Don't store any configuration if the layout is disabled.
326
    if (!empty($row->disabled)) {
327
      continue;
328
    }
329

    
330
    // Don't store any configuration with layouts that don't exist anymore.
331
    if (!isset($ds_layouts[$row->layout])) {
332
      continue;
333
    }
334

    
335
    // Don't store any configuration if the entity type is not defined.
336
    if (!isset($entity_info[$row->entity_type])) {
337
      continue;
338
    }
339

    
340
    // Don't store any configuration if the bundle doesn't exist.
341
    if (!isset($entity_info[$row->entity_type]['bundles'][$row->bundle])) {
342
      continue;
343
    }
344

    
345
    $layout = $ds_layouts[$row->layout];
346
    $layout['layout'] = $row->layout;
347
    $layout['settings'] = $row->settings;
348
    $entity_info[$row->entity_type]['bundles'][$row->bundle]['layouts'][$row->view_mode] = $layout;
349
  }
350

    
351

    
352
  $revision = array(
353
    'label' => 'Revision',
354
    'custom settings' => FALSE,
355
  );
356
  $entity_info['node']['view modes']['revision'] = $revision;
357
}
358

    
359
/**
360
 * Implements hook_ds_layout_info().
361
 */
362
function _ds_ds_layout_info() {
363
  $path = drupal_get_path('module', 'ds');
364
  $layouts = array(
365
    'ds_1col' => array(
366
      'label' => t('One column'),
367
      'path' => $path . '/layouts/ds_1col',
368
      'regions' => array(
369
        'ds_content' => t('Content'),
370
      ),
371
      'image' => TRUE,
372
    ),
373
    'ds_1col_wrapper' => array(
374
      'label' => t('One column + wrapper'),
375
      'path' => $path . '/layouts/ds_1col_wrapper',
376
      'regions' => array(
377
        'ds_content' => t('Content'),
378
      ),
379
      'image' => TRUE,
380
    ),
381
    'ds_2col' => array(
382
      'label' => t('Two column'),
383
      'path' => $path . '/layouts/ds_2col',
384
      'regions' => array(
385
        'left' => t('Left'),
386
        'right' => t('Right')
387
      ),
388
      'css' => TRUE,
389
      'image' => TRUE,
390
    ),
391
    'ds_2col_fluid' => array(
392
      'label' => t('Fluid two column'),
393
      'path' => $path . '/layouts/ds_2col_fluid',
394
      'regions' => array(
395
        'left' => t('Left'),
396
        'right' => t('Right')
397
      ),
398
      'css' => TRUE,
399
      'image' => TRUE,
400
    ),
401
    'ds_2col_stacked' => array(
402
      'label' => t('Two column stacked'),
403
      'path' => $path . '/layouts/ds_2col_stacked',
404
      'regions' => array(
405
        'header' => t('Header'),
406
        'left' => t('Left'),
407
        'right' => t('Right'),
408
        'footer' => t('Footer'),
409
      ),
410
      'css' => TRUE,
411
      'image' => TRUE,
412
    ),
413
    'ds_2col_stacked_fluid' => array(
414
      'label' => t('Fluid two column stacked'),
415
      'path' => $path . '/layouts/ds_2col_stacked_fluid',
416
      'regions' => array(
417
        'header' => t('Header'),
418
        'left' => t('Left'),
419
        'right' => t('Right'),
420
        'footer' => t('Footer'),
421
      ),
422
      'css' => TRUE,
423
      'image' => TRUE,
424
    ),
425
    'ds_3col' => array(
426
      'label' => t('Three column - 25/50/25'),
427
      'path' => $path . '/layouts/ds_3col',
428
      'regions' => array(
429
        'left' => t('Left'),
430
        'middle' => t('Middle'),
431
        'right' => t('Right'),
432
      ),
433
      'css' => TRUE,
434
      'image' => TRUE,
435
    ),
436
    'ds_3col_equal_width' => array(
437
      'label' => t('Three column - equal width'),
438
      'path' => $path . '/layouts/ds_3col_equal_width',
439
      'regions' => array(
440
        'left' => t('Left'),
441
        'middle' => t('Middle'),
442
        'right' => t('Right'),
443
      ),
444
      'css' => TRUE,
445
      'image' => TRUE,
446
    ),
447
    'ds_3col_stacked' => array(
448
      'label' => t('Three column stacked - 25/50/25'),
449
      'path' => $path . '/layouts/ds_3col_stacked',
450
      'regions' => array(
451
        'header' => t('Header'),
452
        'left' => t('Left'),
453
        'middle' => t('Middle'),
454
        'right' => t('Right'),
455
        'footer' => t('Footer'),
456
      ),
457
      'css' => TRUE,
458
      'image' => TRUE,
459
    ),
460
    'ds_3col_stacked_fluid' => array(
461
      'label' => t('Fluid three column stacked - 25/50/25'),
462
      'path' => $path . '/layouts/ds_3col_stacked_fluid',
463
      'regions' => array(
464
        'header' => t('Header'),
465
        'left' => t('Left'),
466
        'middle' => t('Middle'),
467
        'right' => t('Right'),
468
        'footer' => t('Footer'),
469
      ),
470
      'css' => TRUE,
471
      'image' => TRUE,
472
    ),
473
    'ds_3col_stacked_equal_width' => array(
474
      'label' => t('Three column stacked - equal width'),
475
      'path' => $path . '/layouts/ds_3col_stacked_equal_width',
476
      'regions' => array(
477
        'header' => t('Header'),
478
        'left' => t('Left'),
479
        'middle' => t('Middle'),
480
        'right' => t('Right'),
481
        'footer' => t('Footer'),
482
      ),
483
      'css' => TRUE,
484
      'image' => TRUE,
485
    ),
486
    'ds_4col' => array(
487
      'label' => t('Four column - equal width'),
488
      'path' => $path . '/layouts/ds_4col',
489
      'regions' => array(
490
        'first' => t('First'),
491
        'second' => t('Second'),
492
        'third' => t('Third'),
493
        'fourth' => t('Fourth'),
494
      ),
495
      'css' => TRUE,
496
      'image' => TRUE,
497
    ),
498
    'ds_reset' => array(
499
      'label' => t('Reset'),
500
      'path' => $path . '/layouts/ds_reset',
501
      'regions' => array(
502
        'ds_content' => t('Content'),
503
      ),
504
      'image' => TRUE,
505
    ),
506
  );
507

    
508
  // Support for panels.
509
  if (module_exists('panels')) {
510
    ctools_include('plugins', 'panels');
511
    $panel_layouts = panels_get_layouts();
512
    foreach ($panel_layouts as $key => $layout) {
513
      // The easy ones.
514
      if (isset($layout['regions'])) {
515
        $layouts['panels-' . $key] = array(
516
          'label' => $layout['title'],
517
          'path' => $layout['path'],
518
          'module' => 'panels',
519
          // We need the Panels plugin info array to correctly include the
520
          // layout and its CSS files later on.
521
          'panels' => $layout,
522
          'flexible' => FALSE,
523
          'regions' => $layout['regions'],
524
        );
525
        if (!empty($layout['css'])) {
526
          $layouts['panels-' . $key]['css'] = TRUE;
527
        }
528
      }
529
      // Flexible panel layouts, ignore the default flexible.
530
      else {
531
        if ($layout['name'] != 'flexible') {
532
          $regions = panels_flexible_panels(array(), array(), $layout);
533
          $layouts['panels-' . $key] = array(
534
            'label' => $layout['title'],
535
            'path' => $layout['path'],
536
            'module' => 'panels',
537
            'panels' => $layout,
538
            'flexible' => TRUE,
539
            'regions' => $regions,
540
          );
541
        }
542
      }
543
    }
544
  }
545

    
546
  // Get layouts defined in the active theme and base theme (if applicable).
547
  $themes = list_themes();
548
  $theme = variable_get('theme_default', 'bartik');
549

    
550
  $base_theme = array();
551
  $ancestor = $theme;
552
  while ($ancestor && isset($themes[$ancestor]->base_theme)) {
553
    $ancestor = $themes[$ancestor]->base_theme;
554
    $base_theme[] = $themes[$ancestor];
555
  }
556

    
557
  foreach (array_reverse($base_theme) as $base) {
558
    _ds_layouts_scan_theme($base->name, $layouts);
559
  }
560
  _ds_layouts_scan_theme($theme, $layouts);
561

    
562
  return $layouts;
563
}
564

    
565
function _ds_layouts_scan_theme($theme, &$layouts) {
566
  $theme_layouts = file_scan_directory(drupal_get_path('theme', $theme) . '/ds_layouts', '/inc$/');
567
  foreach ($theme_layouts as $file => $values) {
568
    include_once(DRUPAL_ROOT . '/' . $file);
569
    $function = 'ds_' . $values->name;
570
    $layouts[$values->name] = $function();
571
    $layouts[$values->name]['path'] = str_replace('/' . $values->filename, '', $file);
572
  }
573
}
574

    
575
/**
576
 * Implements hook_menu_alter().
577
 */
578
function _ds_menu_alter(&$items) {
579
  // Do not conflict with the revisioning module.
580
  if (module_exists('revisioning')) {
581
    $items['node/%node/revisions/%vid/view']['page callback'] = 'ds_revision_node_show';
582
    $items['node/%node/revisions/%vid/view']['file'] = 'includes/ds.revision.inc';
583
    $items['node/%node/revisions/%vid/view']['file path'] = drupal_get_path('module', 'ds');
584
  }
585
  else {
586
    $items['node/%node/revisions/%/view']['page callback'] = 'ds_revision_node_show';
587
    $items['node/%node/revisions/%/view']['file'] = 'includes/ds.revision.inc';
588
    $items['node/%node/revisions/%/view']['file path'] = drupal_get_path('module', 'ds');
589
  }
590
}