1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
|
<?php
/**
* @file
* Registry file for Display Suite.
*/
/**
* Implements hook_menu().
*/
function _ds_menu() {
$items = array();
// Layout overview.
$items['admin/structure/ds'] = array(
'title' => 'Display Suite',
'description' => 'Manage layouts for entities and configure fields, view modes etc.',
'page callback' => 'ds_layout_list',
'file' => 'includes/ds.displays.inc',
'access arguments' => array('admin_display_suite'),
);
// Layout overview, primary tab.
$items['admin/structure/ds/list'] = array(
'title' => 'Displays',
'weight' => -10,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
// Layout overview, secondary tab.
$items['admin/structure/ds/list/list'] = array(
'title' => 'List',
'weight' => -10,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
// Emergency page
$items['admin/structure/ds/list/emergency'] = array(
'title' => 'Emergency',
'description' => 'In case you have errors via Display Suite, visit this page.',
'page callback' => 'drupal_get_form',
'page arguments' => array('ds_emergency'),
'access arguments' => array('admin_display_suite'),
'file' => 'includes/ds.displays.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 100,
);
// Change layout.
$items['admin/structure/ds/change-layout'] = array(
'title' => 'Change layout',
'description' => 'Act on layout change to move fields elsewhere',
'page callback' => 'drupal_get_form',
'page arguments' => array('ds_field_ui_layout_change'),
'access arguments' => array('admin_display_suite'),
'file' => 'includes/ds.field_ui.inc',
'type' => MENU_VISIBLE_IN_BREADCRUMB,
);
// Revert layout.
$items['admin/structure/ds/revert-layout'] = array(
'title' => 'Revert layout',
'description' => 'Revert layout and field settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('ds_revert_layout_field_settings_form'),
'file' => 'includes/ds.field_ui.inc',
'access arguments' => array('admin_display_suite'),
'type' => MENU_VISIBLE_IN_BREADCRUMB,
);
// Disable layout.
$items['admin/structure/ds/disable'] = array(
'title' => 'Disable layout',
'description' => 'Disable layout and field settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('ds_disable_layout_field_settings_form'),
'file' => 'includes/ds.field_ui.inc',
'access arguments' => array('admin_display_suite'),
'type' => MENU_VISIBLE_IN_BREADCRUMB,
);
// Enable layout.
$items['admin/structure/ds/enable'] = array(
'title' => 'Enable layout',
'description' => 'Enable layout and field settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('ds_enable_layout_field_settings_form'),
'file' => 'includes/ds.field_ui.inc',
'access arguments' => array('admin_display_suite'),
'type' => MENU_VISIBLE_IN_BREADCRUMB,
);
// CTools content.
$items['admin/structure/ds/fields/manage_ctools/content'] = array(
'title' => 'Ctools field content',
'page callback' => 'ds_ctools_content',
'file' => 'includes/ds.field_ui.inc',
'access arguments' => array('admin_display_suite'),
'type' => MENU_CALLBACK,
);
// Contextual links.
if (module_exists('contextual') && module_exists('field_ui')) {
$items['node/%node/display'] = array(
'title' => 'Manage display',
'description' => 'Manage display of this content.',
'page callback' => 'ds_contextual_page_tab',
'page arguments' => array(1, 'node'),
'file' => 'includes/ds.contextual.inc',
'access arguments' => array('administer content types'),
'type' => MENU_LOCAL_TASK,
);
$items['user/%user/display'] = array(
'title' => 'Manage display',
'description' => 'Manage display of this user profile.',
'page callback' => 'ds_contextual_page_tab',
'page arguments' => array(1, 'user'),
'file' => 'includes/ds.contextual.inc',
'access arguments' => array('administer users'),
'type' => MENU_LOCAL_TASK,
);
if (module_exists('taxonomy')) {
$items['taxonomy/term/%taxonomy_term/display'] = array(
'title' => 'Manage display',
'description' => 'Manage display of this term.',
'page callback' => 'ds_contextual_page_tab',
'page arguments' => array(2, 'taxonomy_term'),
'access arguments' => array('administer taxonomy'),
'type' => MENU_LOCAL_TASK,
'weight' => 11,
'file' => 'includes/ds.contextual.inc',
);
}
}
return $items;
}
/**
* Implements hook_theme().
*/
function _ds_theme() {
$theme_functions = array();
// Layouts
$layouts = ds_get_layout_info();
foreach ($layouts as $key => $layout) {
// We don't need panel layouts to be registered.
if (isset($layout['module']) && $layout['module'] == 'panels') {
continue;
}
$theme_functions[$key] = array(
'render element' => 'elements',
'template' => strtr($key, '_', '-'),
'path' => $layout['path'],
);
}
// Field templates
$field_functions = module_invoke_all('ds_field_theme_functions_info');
foreach ($field_functions as $key => $label) {
$theme_functions[$key] = array(
'render element' => 'element',
'function' => $key,
);
}
return $theme_functions;
}
/**
* Implements hook_features_api().
*/
function _ds_features_api() {
static $api = FALSE;
if (!$api) {
module_load_include('inc', 'features', 'includes/features.ctools');
$api = ctools_component_features_api('ds');
foreach ($api as $key => $value) {
switch ($key) {
case 'ds_field_settings':
$api[$key]['name'] = 'Display Suite field settings';
break;
case 'ds_layout_settings':
$api[$key]['name'] = 'Display Suite layout settings';
break;
case 'ds_view_modes':
$api[$key]['name'] = 'Display Suite view modes';
break;
case 'ds_fields':
$api[$key]['name'] = 'Display Suite fields';
break;
}
}
}
return $api;
}
/**
* Remove or rename layout & field settings on entity machine name update.
*
* @param $entity_type
* The name of the entity type.
* @param $info
* The entity info.
* @param $action
* The action, either update or delete.
*/
function _ds_entity_type_update($entity_type, $info, $action) {
// Delete settings.
if ($action == 'delete') {
db_delete('ds_layout_settings')
->condition('entity_type', $entity_type)
->condition('bundle', $info->type)
->execute();
db_delete('ds_field_settings')
->condition('entity_type', $entity_type)
->condition('bundle', $info->type)
->execute();
}
// Update settings.
if ($action == 'update') {
$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));
foreach ($records as $record) {
$old_id = $entity_type . '|' . $info->old_type . '|' . $record->view_mode;
$new_id = $entity_type . '|' . $info->type . '|' . $record->view_mode;
db_update('ds_layout_settings')
->fields(array(
'id' => $new_id,
'bundle' => $info->type)
)
->condition('id', $old_id)
->execute();
}
$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));
foreach ($records as $record) {
$old_id = $entity_type . '|' . $info->old_type . '|' . $record->view_mode;
$new_id = $entity_type . '|' . $info->type . '|' . $record->view_mode;
db_update('ds_field_settings')
->fields(array(
'id' => $new_id,
'bundle' => $info->type)
)
->condition('id', $old_id)
->execute();
}
}
// Clear cache.
cache_clear_all('ds_fields:', 'cache', TRUE);
cache_clear_all('ds_field_settings', 'cache');
field_info_cache_clear();
}
/**
* Implements hook_theme_registry_alter().
*/
function _ds_theme_registry_alter(&$theme_registry) {
// Inject ds_entity_variables in all entity theming functions.
$entity_info = entity_get_info();
foreach ($entity_info as $entity => $info) {
if (isset($entity_info[$entity]['fieldable']) && $entity_info[$entity]['fieldable']) {
// User uses user_profile for theming.
if ($entity == 'user') $entity = 'user_profile';
// Only add preprocess functions if entity exposes theme function.
if (isset($theme_registry[$entity])) {
$theme_registry[$entity]['preprocess functions'][] = 'ds_entity_variables';
}
}
}
// Support for File Entity.
if (isset($theme_registry['file_entity'])) {
$theme_registry['file_entity']['preprocess functions'][] = 'ds_entity_variables';
}
// Support for Entity API.
if (isset($theme_registry['entity'])) {
$theme_registry['entity']['preprocess functions'][] = 'ds_entity_variables';
}
}
/**
* Implements hook_entity_info_alter().
*/
function _ds_entity_info_alter(&$entity_info) {
// Make sure ds_view_modes table exists.
if (!db_table_exists('ds_view_modes')) {
return;
}
ctools_include('export');
// Add custom view modes to entities.
$custom_view_modes = ctools_export_crud_load_all('ds_view_modes');
foreach ($custom_view_modes as $view_mode_key => $view_mode_value) {
$view_mode = array(
'label' => check_plain($view_mode_value->label),
'custom settings' => FALSE,
);
foreach ($view_mode_value->entities as $entity_type) {
if (isset($entity_info[$entity_type])) {
$entity_info[$entity_type]['view modes'][$view_mode_key] = $view_mode;
}
}
}
// Add layout if applicable.
$ds_layouts = ds_get_layout_info();
$ds_layout_settings = ctools_export_crud_load_all('ds_layout_settings');
foreach ($ds_layout_settings as $row) {
// Don't store any configuration if the layout is disabled.
if (!empty($row->disabled)) {
continue;
}
// Don't store any configuration with layouts that don't exist anymore.
if (!isset($ds_layouts[$row->layout])) {
continue;
}
// Don't store any configuration if the entity type is not defined.
if (!isset($entity_info[$row->entity_type])) {
continue;
}
// Don't store any configuration if the bundle doesn't exist.
if (!isset($entity_info[$row->entity_type]['bundles'][$row->bundle])) {
continue;
}
$layout = $ds_layouts[$row->layout];
$layout['layout'] = $row->layout;
$layout['settings'] = $row->settings;
$entity_info[$row->entity_type]['bundles'][$row->bundle]['layouts'][$row->view_mode] = $layout;
}
$revision = array(
'label' => 'Revision',
'custom settings' => FALSE,
);
$entity_info['node']['view modes']['revision'] = $revision;
}
/**
* Implements hook_ds_layout_info().
*/
function _ds_ds_layout_info() {
$path = drupal_get_path('module', 'ds');
$layouts = array(
'ds_1col' => array(
'label' => t('One column'),
'path' => $path . '/layouts/ds_1col',
'regions' => array(
'ds_content' => t('Content'),
),
'image' => TRUE,
),
'ds_1col_wrapper' => array(
'label' => t('One column + wrapper'),
'path' => $path . '/layouts/ds_1col_wrapper',
'regions' => array(
'ds_content' => t('Content'),
),
'image' => TRUE,
),
'ds_2col' => array(
'label' => t('Two column'),
'path' => $path . '/layouts/ds_2col',
'regions' => array(
'left' => t('Left'),
'right' => t('Right')
),
'css' => TRUE,
'image' => TRUE,
),
'ds_2col_fluid' => array(
'label' => t('Fluid two column'),
'path' => $path . '/layouts/ds_2col_fluid',
'regions' => array(
'left' => t('Left'),
'right' => t('Right')
),
'css' => TRUE,
'image' => TRUE,
),
'ds_2col_stacked' => array(
'label' => t('Two column stacked'),
'path' => $path . '/layouts/ds_2col_stacked',
'regions' => array(
'header' => t('Header'),
'left' => t('Left'),
'right' => t('Right'),
'footer' => t('Footer'),
),
'css' => TRUE,
'image' => TRUE,
),
'ds_2col_stacked_fluid' => array(
'label' => t('Fluid two column stacked'),
'path' => $path . '/layouts/ds_2col_stacked_fluid',
'regions' => array(
'header' => t('Header'),
'left' => t('Left'),
'right' => t('Right'),
'footer' => t('Footer'),
),
'css' => TRUE,
'image' => TRUE,
),
'ds_3col' => array(
'label' => t('Three column - 25/50/25'),
'path' => $path . '/layouts/ds_3col',
'regions' => array(
'left' => t('Left'),
'middle' => t('Middle'),
'right' => t('Right'),
),
'css' => TRUE,
'image' => TRUE,
),
'ds_3col_equal_width' => array(
'label' => t('Three column - equal width'),
'path' => $path . '/layouts/ds_3col_equal_width',
'regions' => array(
'left' => t('Left'),
'middle' => t('Middle'),
'right' => t('Right'),
),
'css' => TRUE,
'image' => TRUE,
),
'ds_3col_stacked' => array(
'label' => t('Three column stacked - 25/50/25'),
'path' => $path . '/layouts/ds_3col_stacked',
'regions' => array(
'header' => t('Header'),
'left' => t('Left'),
'middle' => t('Middle'),
'right' => t('Right'),
'footer' => t('Footer'),
),
'css' => TRUE,
'image' => TRUE,
),
'ds_3col_stacked_fluid' => array(
'label' => t('Fluid three column stacked - 25/50/25'),
'path' => $path . '/layouts/ds_3col_stacked_fluid',
'regions' => array(
'header' => t('Header'),
'left' => t('Left'),
'middle' => t('Middle'),
'right' => t('Right'),
'footer' => t('Footer'),
),
'css' => TRUE,
'image' => TRUE,
),
'ds_3col_stacked_equal_width' => array(
'label' => t('Three column stacked - equal width'),
'path' => $path . '/layouts/ds_3col_stacked_equal_width',
'regions' => array(
'header' => t('Header'),
'left' => t('Left'),
'middle' => t('Middle'),
'right' => t('Right'),
'footer' => t('Footer'),
),
'css' => TRUE,
'image' => TRUE,
),
'ds_4col' => array(
'label' => t('Four column - equal width'),
'path' => $path . '/layouts/ds_4col',
'regions' => array(
'first' => t('First'),
'second' => t('Second'),
'third' => t('Third'),
'fourth' => t('Fourth'),
),
'css' => TRUE,
'image' => TRUE,
),
'ds_reset' => array(
'label' => t('Reset'),
'path' => $path . '/layouts/ds_reset',
'regions' => array(
'ds_content' => t('Content'),
),
'image' => TRUE,
),
);
// Support for panels.
if (module_exists('panels')) {
ctools_include('plugins', 'panels');
$panel_layouts = panels_get_layouts();
foreach ($panel_layouts as $key => $layout) {
// The easy ones.
if (isset($layout['regions'])) {
$layouts['panels-' . $key] = array(
'label' => $layout['title'],
'path' => $layout['path'],
'module' => 'panels',
// We need the Panels plugin info array to correctly include the
// layout and its CSS files later on.
'panels' => $layout,
'flexible' => FALSE,
'regions' => $layout['regions'],
);
if (!empty($layout['css'])) {
$layouts['panels-' . $key]['css'] = TRUE;
}
}
// Flexible panel layouts, ignore the default flexible.
else {
if ($layout['name'] != 'flexible') {
$regions = panels_flexible_panels(array(), array(), $layout);
$layouts['panels-' . $key] = array(
'label' => $layout['title'],
'path' => $layout['path'],
'module' => 'panels',
'panels' => $layout,
'flexible' => TRUE,
'regions' => $regions,
);
}
}
}
}
// Get layouts defined in the active theme and base theme (if applicable).
$themes = list_themes();
$theme = variable_get('theme_default', 'bartik');
$base_theme = array();
$ancestor = $theme;
while ($ancestor && isset($themes[$ancestor]->base_theme)) {
$ancestor = $themes[$ancestor]->base_theme;
$base_theme[] = $themes[$ancestor];
}
foreach (array_reverse($base_theme) as $base) {
_ds_layouts_scan_theme($base->name, $layouts);
}
_ds_layouts_scan_theme($theme, $layouts);
return $layouts;
}
function _ds_layouts_scan_theme($theme, &$layouts) {
$theme_layouts = file_scan_directory(drupal_get_path('theme', $theme) . '/ds_layouts', '/inc$/');
foreach ($theme_layouts as $file => $values) {
include_once(DRUPAL_ROOT . '/' . $file);
$function = 'ds_' . $values->name;
$layouts[$values->name] = $function();
$layouts[$values->name]['path'] = str_replace('/' . $values->filename, '', $file);
}
}
/**
* Implements hook_menu_alter().
*/
function _ds_menu_alter(&$items) {
// Do not conflict with the revisioning module.
if (module_exists('revisioning')) {
$items['node/%node/revisions/%vid/view']['page callback'] = 'ds_revision_node_show';
$items['node/%node/revisions/%vid/view']['file'] = 'includes/ds.revision.inc';
$items['node/%node/revisions/%vid/view']['file path'] = drupal_get_path('module', 'ds');
}
else {
$items['node/%node/revisions/%/view']['page callback'] = 'ds_revision_node_show';
$items['node/%node/revisions/%/view']['file'] = 'includes/ds.revision.inc';
$items['node/%node/revisions/%/view']['file path'] = drupal_get_path('module', 'ds');
}
}
|