Projet

Général

Profil

Paste
Télécharger (25 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ds / modules / ds_extras / includes / ds_extras.admin.inc @ 3dfa8105

1
<?php
2

    
3
/**
4
 * @file
5
 * Display Suite Extras administrative functions.
6
 */
7

    
8
/**
9
 * Menu callback: Display Suite extras settings.
10
 */
11
function ds_extras_settings($form) {
12

    
13
  $form['additional_settings'] = array(
14
    '#type' => 'vertical_tabs',
15
    '#theme_wrappers' => array('vertical_tabs'),
16
    '#prefix' => '<div>',
17
    '#suffix' => '</div>',
18
    '#tree' => TRUE,
19
  );
20

    
21
  $form['additional_settings']['fs1'] = array(
22
    '#type' => 'fieldset',
23
    '#title' => t('Field Templates'),
24
  );
25

    
26
  $form['additional_settings']['fs1']['ds_extras_field_template'] = array(
27
    '#type' => 'checkbox',
28
    '#title' => t('Enable Field Templates'),
29
    '#description' => t('Customize the labels and the HTML output of your fields.'),
30
    '#default_value' => variable_get('ds_extras_field_template', FALSE),
31
  );
32

    
33
  $theme_functions = module_invoke_all('ds_field_theme_functions_info');
34
  $form['additional_settings']['fs1']['ft-default'] = array(
35
    '#type' => 'select',
36
    '#title' => t('Default Field Template'),
37
    '#options' => $theme_functions,
38
    '#default_value' => variable_get('ft-default', 'theme_field'),
39
    '#description' => t('Default will output the field as defined in Drupal Core.<br />Reset will strip all HTML.<br />Minimal adds a simple wrapper around the field.<br/>There is also an Expert Field Template that gives full control over the HTML, but can only be set per field.<br /><br />You can override this setting per field on the "Manage display" screens or when creating fields on the instance level.<br /><br /><strong>Template suggestions</strong><br />You can create .tpl files as well for these field theme functions, e.g. field--reset.tpl.php, field--minimal.tpl.php<br /><br /><label>CSS classes</label>You can add custom CSS classes on the <a href="!url">classes form</a>. Display Suite UI needs to be enabled for this. These classes can be added to fields using the Default Field Template.<br /><br /><label>Advanced</label>You can create your own custom field templates which need to be defined with hook_ds_field_theme_functions_info(). See ds.api.php for an example.', array('!url' => url('admin/structure/ds/classes'))),
40
    '#states' => array(
41
      'visible' => array(
42
        'input[name="additional_settings[fs1][ds_extras_field_template]"]' => array('checked' => TRUE),
43
      ),
44
    ),
45
  );
46

    
47
  $form['additional_settings']['fs1']['ft-kill-colon'] = array(
48
    '#type' => 'checkbox',
49
    '#title' => t('Hide colon'),
50
    '#default_value' => variable_get('ft-kill-colon', FALSE),
51
    '#description' => t('Hide the colon on the reset field template.'),
52
    '#states' => array(
53
      'visible' => array(
54
        'select[name="additional_settings[fs1][ft-default]"]' => array('value' => 'theme_ds_field_reset'),
55
        'input[name="additional_settings[fs1][ds_extras_field_template]"]' => array('checked' => TRUE),
56
      ),
57
    ),
58
  );
59

    
60

    
61
  $form['additional_settings']['fs2'] = array(
62
    '#type' => 'fieldset',
63
    '#title' => t('Extra fields'),
64
  );
65

    
66
  $form['additional_settings']['fs2']['ds_extras_fields_extra'] = array(
67
    '#type' => 'checkbox',
68
    '#title' => t('Enable extra fields'),
69
    '#description' => t('Make fields from other modules available on the "Manage display" screens.'),
70
    '#default_value' => variable_get('ds_extras_fields_extra', FALSE),
71
  );
72

    
73
  $form['additional_settings']['fs2']['ds_extras_fields_extra_list'] = array(
74
    '#type' => 'textarea',
75
    '#description' => t('Enter fields line by line, where each line is a combination of entity type, bundle and field name. E.g. node|article|tweetbutton. It might be possible that the actual content of the field depends on configuration of that field/module.'),
76
    '#default_value' => variable_get('ds_extras_fields_extra_list', FALSE),
77
    '#states' => array(
78
      'visible' => array(
79
        'input[name="additional_settings[fs2][ds_extras_fields_extra]"]' => array('checked' => TRUE),
80
      ),
81
    ),
82
  );
83

    
84
  $form['additional_settings']['fs4'] = array(
85
    '#type' => 'fieldset',
86
    '#title' => t('Other'),
87
  );
88

    
89
  $form['additional_settings']['fs4']['ds_extras_switch_view_mode'] = array(
90
    '#type' => 'checkbox',
91
    '#title' => t('View mode per node'),
92
    '#description' => t('Change view modes for individual nodes. A new tab \'Display settings\' will appear on the content create form.<br />You can also pass the name of a view mode through the URL, eg node/x?v=full.<br />If you install the Page manager module and override the node view, Page manager will win.'),
93
    '#default_value' => variable_get('ds_extras_switch_view_mode', FALSE),
94
  );
95

    
96
  $form['additional_settings']['fs4']['ds_extras_hide_page_title'] = array(
97
    '#type' => 'checkbox',
98
    '#title' => t('Page title options'),
99
    '#description' => t('Hide or manually set the page title of the "Full content" view mode.'),
100
    '#default_value' => variable_get('ds_extras_hide_page_title', FALSE),
101
  );
102

    
103
  $form['additional_settings']['fs4']['ds_extras_hide_page_sidebars'] = array(
104
    '#type' => 'checkbox',
105
    '#title' => t('Disable Drupal blocks/regions'),
106
    '#description' => t('Add ability to disable all sidebar regions displayed in the theme. Note that some themes support this setting better than others. If in doubt, try with stock themes to see.'),
107
    '#default_value' => variable_get('ds_extras_hide_page_sidebars', FALSE),
108
  );
109

    
110
  $form['additional_settings']['fs4']['ds_extras_field_permissions'] = array(
111
    '#type' => 'checkbox',
112
    '#title' => t('Field permissions'),
113
    '#description' => t('Enables view permissions on all Display Suite fields.'),
114
    '#default_value' => variable_get('ds_extras_field_permissions', FALSE),
115
  );
116

    
117
  $form['additional_settings']['fs4']['ds_extras_region_to_block'] = array(
118
    '#type' => 'checkbox',
119
    '#title' => t('Region to block'),
120
    '#description' => t('Create additional regions exposed as block. Note: this will not work on the default view mode.'),
121
    '#default_value' => variable_get('ds_extras_region_to_block', FALSE),
122
  );
123

    
124
  if (module_exists('views')) {
125
    $form['additional_settings']['fs4']['ds_extras_vd'] = array(
126
      '#type' => 'checkbox',
127
      '#title' => t('Views displays'),
128
      '#description' => t('Manage the layout of your Views layout with Field UI at !url.', array('!url' => l(url('admin/structure/ds/vd', array('absolute' => TRUE)), 'admin/structure/ds/vd'))),
129
      '#default_value' => variable_get('ds_extras_vd', FALSE),
130
    );
131
  }
132

    
133
  if (module_exists('flag')) {
134
    $form['additional_settings']['fs4']['ds_extras_flag'] = array(
135
      '#type' => 'checkbox',
136
      '#title' => t('Flag'),
137
      '#description' => t('Expose flags as fields on nodes.'),
138
      '#default_value' => variable_get('ds_extras_flag', FALSE),
139
    );
140
  }
141

    
142
  $form['additional_settings']['fs4']['ds_extras_switch_field'] = array(
143
    '#type' => 'checkbox',
144
    '#title' => t('View mode switcher'),
145
    '#description' => t('Adds a field with links to switch view modes inline with Ajax. Only works for nodes at this time.'),
146
    '#default_value' => variable_get('ds_extras_switch_field', FALSE),
147
  );
148

    
149
  $form['additional_settings']['fs4']['ds_extras_hidden_region'] = array(
150
    '#type' => 'checkbox',
151
    '#title' => t('Hidden region'),
152
    '#description' => t('Add a hidden region to the layouts. Fields will be built but not printed.'),
153
    '#default_value' => variable_get('ds_extras_hidden_region', FALSE),
154
  );
155

    
156
  $form['#attached']['js'][] = drupal_get_path('module', 'ds_extras') . '/js/ds_extras.admin.js';
157

    
158
  $form = system_settings_form($form);
159
  $form['#submit'][] = 'ds_extras_settings_submit';
160
  return $form;
161
}
162

    
163
/**
164
 * Validate callback: Extras settings screen.
165
 */
166
function ds_extras_settings_validate($form, &$form_state) {
167
  foreach ($form_state['values']['additional_settings'] as $tab => $value) {
168
    if (is_array($value)) {
169
      foreach ($value as $variable => $val) {
170
        $form_state['values'][$variable] = $val;
171
      }
172
    }
173
    unset($form_state['values']['additional_settings'][$tab]);
174
  }
175
  unset($form_state['values']['additional_settings']);
176
}
177

    
178
/**
179
 * Submit callback: Extras settings screen.
180
 */
181
function ds_extras_settings_submit($form, &$form_state) {
182
  cache_clear_all('ds_fields:', 'cache', TRUE);
183
  cache_clear_all('entity_info:', 'cache', TRUE);
184
  cache_clear_all('theme_registry:', 'cache', TRUE);
185
  cache_clear_all('module_implements', 'cache_bootstrap');
186
  cache_clear_all('field_info_fields', 'cache_field');
187
  variable_set('menu_rebuild_needed', TRUE);
188
}
189

    
190
/**
191
 * Alter Manage display screen.
192
 */
193
function ds_extras_field_ui_alter(&$form, &$form_state) {
194
  // Attach js.
195
  $form['#attached']['js'][] = drupal_get_path('module', 'ds_extras') . '/js/ds_extras.admin.js';
196

    
197
  // Views displays.
198
  if ($form['#entity_type'] == 'ds_views') {
199
    // Add an additional submit callback so we can ditch the extra title
200
    // which is added by ds_extras_field_extra_fields().
201
    $form['#submit'] = array_merge(array('ds_extras_vd_field_ui_submit'), $form['#submit']);
202
  }
203

    
204
  // Page title functionality, currently only works on nodes, users and taxonomy terms.
205
  if (variable_get('ds_extras_hide_page_title', FALSE) && isset($form['#ds_layout']) && (in_array($form['#entity_type'], array('node', 'user', 'taxonomy_term', 'profile2')) && ($form['#view_mode'] == 'full' || $form['#view_mode'] == 'revision' ||  (variable_get('ds_extras_switch_view_mode', FALSE) && $form['#entity_type'] == 'node')) || $form['#entity_type'] == 'ds_views' || $form['#entity_type'] == 'profile2')) {
206
    $form['additional_settings']['ds_page_title'] = array(
207
      '#type' => 'fieldset',
208
      '#title' => t('Custom page title'),
209
    );
210
    $form['additional_settings']['ds_page_title']['ds_page_title_options'] = _ds_extras_page_title_options($form['#ds_layout']->settings, $form['#entity_type']);
211
  }
212

    
213
  // Disable page regions.
214
  if (variable_get('ds_extras_hide_page_sidebars', FALSE) && isset($form['#ds_layout']) && $form['#view_mode'] != 'form') {
215
    $form['additional_settings']['ds_layouts']['hide_sidebars'] = array(
216
      '#type' => 'checkbox',
217
      '#title' => t('Disable Drupal blocks/regions'),
218
      '#default_value' => isset($form['#ds_layout']->settings['hide_sidebars']) ? $form['#ds_layout']->settings['hide_sidebars'] : FALSE,
219
      '#weight' => 3,
220
    );
221
  }
222

    
223
  // Region to block only fires if there is a layout and we're working on the
224
  // a view mode which is not equal to default.
225
  if (isset($form['#ds_layout']) && $form['#view_mode'] != 'default' && variable_get('ds_extras_region_to_block', FALSE)) {
226

    
227
    $layout = $form['#ds_layout'];
228

    
229
    // Get the entity_type, bundle and view mode.
230
    $entity_type = $form['#entity_type'];
231
    $bundle = $form['#bundle'];
232
    $view_mode = $form['#view_mode'];
233

    
234
    $region_blocks_options = array();
235
    $region_blocks = variable_get('ds_extras_region_blocks', array());
236
    foreach ($region_blocks as $key => $block) {
237
      if ($block['info'] == "{$entity_type}_{$bundle}_{$view_mode}") {
238
        $region_blocks_options[$key] = t('Remove') . ' ' . $block['title'];
239
      }
240
    }
241

    
242
    $form['additional_settings']['region_to_block'] = array(
243
      '#type' => 'fieldset',
244
      '#title' => t('Block regions'),
245
      '#description' => t('Create additional regions in this layout which will be exposed as blocks. Note that preprocess fields will fail to print.')
246
    );
247

    
248
    $form['additional_settings']['region_to_block']['new_block_region'] = array(
249
      '#type' => 'textfield',
250
      '#title' => t('Region name'),
251
      '#description' => t('Enter a name to create a new region.'),
252
    );
253
    $form['additional_settings']['region_to_block']['new_block_region_key'] = array(
254
      '#title' => t('Machine name'),
255
      '#type' => 'machine_name',
256
      '#default_value' => '',
257
      '#maxlength' => 32,
258
      '#required' => FALSE,
259
      '#description' => t('The machine-readable name of this block region. This name must contain only lowercase letters and underscores. This name must be unique.'),
260
      '#disabled' => FALSE,
261
      '#machine_name' => array(
262
        'exists' => 'ds_extras_region_to_block_unique',
263
        'source' => array('additional_settings', 'region_to_block', 'new_block_region'),
264
      ),
265
    );
266

    
267
    if (!empty($region_blocks_options)) {
268
      $form['additional_settings']['region_to_block']['remove_block_region'] = array(
269
        '#type' => 'checkboxes',
270
        '#title' => t('Existing block regions'),
271
        '#options' => $region_blocks_options,
272
        '#description' => t('Check the regions you want to remove.'),
273
      );
274
    }
275

    
276
    $form['#submit'][] = 'ds_extras_block_submit';
277
  }
278
}
279

    
280
/**
281
 * Field template settings form
282
 */
283
function ds_extras_field_template_settings_form(array &$form, array &$form_state, array $context) {
284
  $functions = module_invoke_all('ds_field_theme_functions_info');
285
  $default_field_function = variable_get('ft-default', 'theme_field');
286
  $key = $context['instance']['field_name'];
287

    
288
  $field_settings = isset($form_state['formatter_settings'][$key]) ? $form_state['formatter_settings'][$key]['ft'] : array();
289

    
290
  $field_function = isset($field_settings['func']) ? $field_settings['func'] : $default_field_function;
291
  $field_classes = _ds_classes('ds_classes_fields');
292

    
293
  $form['ft'] = array(
294
    '#weight' => 20,
295
  );
296

    
297
  // Functions.
298
  $form['ft']['func'] = array(
299
    '#title' => t('Choose a Field Template'),
300
    '#type' => 'select',
301
    '#options' => $functions,
302
    '#default_value' => $field_function,
303
    '#attributes' => array(
304
      'class' => array('ds-extras-field-template'),
305
    ),
306
  );
307

    
308
  // Field classes.
309
  if (!empty($field_classes)) {
310
    $field_classes_select = array(
311
      '#type' => 'select',
312
      '#multiple' => TRUE,
313
      '#options' => $field_classes,
314
      '#title' => t('Choose additional CSS classes for the field'),
315
      '#default_value' => isset($field_settings['classes']) ? explode(' ', $field_settings['classes']) : array(),
316
      '#prefix' => '<div class="field-classes">',
317
      '#suffix' => '</div>',
318
    );
319
    $form['ft']['classes'] = $field_classes_select;
320
  }
321
  else {
322
    $form['ft']['classes'] = array(
323
      '#type' => 'value',
324
      '#value' => array(''),
325
    );
326
  }
327

    
328
  // Add prefix
329
  $form['ft']['prefix'] = array(
330
    '#type' => 'textfield',
331
    '#title' => t('Prefix'),
332
    '#size' => '100',
333
    '#description' => t('You can enter any html in here.'),
334
    '#default_value' => isset($field_settings['prefix']) ? $field_settings['prefix'] : '',
335
    '#prefix' => '<div class="field-prefix">',
336
    '#suffix' => '</div>',
337
  );
338

    
339
  // Wrappers and label.
340
  $wrappers = array(
341
    'lb' => array('title' => t('Label')),
342
    'lbw' => array('title' => t('Label wrapper')),
343
    'ow' => array('title' => t('Outer wrapper')),
344
    'fis' => array('title' => t('Field items')),
345
    'fi' => array('title' => t('Field item')),
346
  );
347

    
348
  foreach ($wrappers as $wrapper_key => $value) {
349

    
350
    $classes = array(
351
      'field-name-' . strtr($key, '_', '-'),
352
    );
353
    $form['ft'][$wrapper_key] = array(
354
      '#type' => 'checkbox',
355
      '#title' => $value['title'],
356
      '#prefix' => '<div class="ft-group ' . $wrapper_key . '">',
357
      '#default_value' => isset($field_settings[$wrapper_key]) ? $field_settings[$wrapper_key] : FALSE,
358
    );
359
    $form['ft'][$wrapper_key . '-el'] = array(
360
      '#type' => 'textfield',
361
      '#title' => t('Element'),
362
      '#size' => '10',
363
      '#description' => t('E.g. div, span, h2 etc.'),
364
      '#default_value' => isset($field_settings[$wrapper_key . '-el']) ? $field_settings[$wrapper_key . '-el'] : '',
365
      '#states' => array(
366
        'visible' => array(
367
          ':input[name$="[ft][' . $wrapper_key . ']"]' => array('checked' => TRUE),
368
        ),
369
      ),
370
    );
371
    $form['ft'][$wrapper_key . '-cl'] = array(
372
      '#type' => 'textfield',
373
      '#title' => t('Classes'),
374
      '#size' => '10',
375
      '#default_value' => isset($field_settings[$wrapper_key . '-cl']) ? $field_settings[$wrapper_key . '-cl'] : '',
376
      '#description' => t('E.g.') .' ' . implode(', ', $classes),
377
      '#states' => array(
378
        'visible' => array(
379
          ':input[name$="[ft][' . $wrapper_key . ']"]' => array('checked' => TRUE),
380
        ),
381
      ),
382
    );
383
    $form['ft'][$wrapper_key . '-at'] = array(
384
      '#type' => 'textfield',
385
      '#title' => t('Attributes'),
386
      '#size' => '20',
387
      '#default_value' => isset($field_settings[$wrapper_key . '-at']) ? $field_settings[$wrapper_key . '-at'] : '',
388
      '#description' => t('E.g. name="anchor"'),
389
      '#states' => array(
390
        'visible' => array(
391
          ':input[name$="[ft][' . $wrapper_key . ']"]' => array('checked' => TRUE),
392
        ),
393
      ),
394
    );
395

    
396
    // Hide colon.
397
    if ($wrapper_key == 'lb') {
398
      $form['ft']['lb-col'] = array(
399
        '#type' => 'checkbox',
400
        '#title' => t('Hide label colon'),
401
        '#default_value' => isset($field_settings['lb-col']) ? $field_settings['lb-col'] : FALSE,
402
        '#attributes' => array(
403
          'class' => array('colon-checkbox'),
404
        ),
405
      );
406
    }
407
    if ($wrapper_key == 'fi') {
408
      $form['ft']['fi-odd-even'] = array(
409
        '#type' => 'checkbox',
410
        '#title' => t('Add odd/even classes'),
411
        '#default_value' => isset($field_settings['fi-odd-even']) ? $field_settings['fi-odd-even'] : FALSE,
412
        '#states' => array(
413
          'visible' => array(
414
            ':input[name$="[ft][' . $wrapper_key . ']"]' => array('checked' => TRUE),
415
          ),
416
        ),
417
      );
418
    }
419
    if ($wrapper_key != 'lbw') {
420
      $form['ft'][$wrapper_key . '-def-at'] = array(
421
        '#type' => 'checkbox',
422
        '#title' => t('Add default attributes'),
423
        '#default_value' => isset($field_settings[$wrapper_key . '-def-at']) ? $field_settings[$wrapper_key . '-def-at'] : FALSE,
424
        '#suffix' => ($wrapper_key == 'ow') ? '' : '</div>',
425
        '#states' => array(
426
          'visible' => array(
427
            ':input[name$="[ft][' . $wrapper_key . ']"]' => array('checked' => TRUE),
428
          ),
429
        ),
430
      );
431
    }
432
    else {
433
      $form['ft'][$wrapper_key . '-def-at'] = array(
434
        '#markup' => '</div><div class="clearfix"></div>',
435
      );
436
    }
437

    
438
    // Default classes for outer wrapper.
439
    if ($wrapper_key == 'ow') {
440
      $form['ft'][$wrapper_key . '-def-cl'] = array(
441
        '#type' => 'checkbox',
442
        '#title' => t('Add default classes'),
443
        '#default_value' => isset($field_settings[$wrapper_key . '-def-cl']) ? $field_settings[$wrapper_key . '-def-cl'] : FALSE,
444
        '#suffix' => '</div>',
445
        '#states' => array(
446
          'visible' => array(
447
            ':input[name$="[ft][' . $wrapper_key . ']"]' => array('checked' => TRUE),
448
          ),
449
        ),
450
      );
451
    }
452
  }
453

    
454
  // Add suffix
455
  $form['ft']['suffix'] = array(
456
    '#type' => 'textfield',
457
    '#title' => t('Suffix'),
458
    '#size' => '100',
459
    '#description' => t('You can enter any html in here.'),
460
    '#default_value' => isset($field_settings['suffix']) ? $field_settings['suffix'] : '',
461
    '#prefix' => '<div class="field-prefix">',
462
    '#suffix' => '</div>',
463
  );
464

    
465
  // Another label needs some other stuff.
466
  unset($form['ft']['lb']['#description']);
467
  $form['ft']['lb']['#type'] = 'textfield';
468
  $form['ft']['lb']['#size'] = '10';
469
  $form['ft']['lb']['#attributes'] = array('class' => array('label-change'));
470
  $form['ft']['lb']['#default_value'] = isset($field_settings['lb']) ? $field_settings['lb'] : '';
471

    
472
  // Let other modules make modifications to the settings form as needed.
473
  drupal_alter('ds_field_theme_functions_settings_form_alter', $form, $field_settings);
474
}
475

    
476
/**
477
 * Implements hook_ds_field_format_summary().
478
 */
479
function ds_extras_ds_field_format_summary($field) {
480
  if (isset($field['formatter_settings'])) {
481
    foreach ($field['formatter_settings'] as $key => $value) {
482
      if (!empty($value)) {
483
        return t('Configured');
484
        break;
485
      }
486
    }
487
  }
488
  return t('Not configured');
489
}
490

    
491
/**
492
 * Implements hook_ds_field_settings_form().
493
 */
494
function ds_extras_ds_field_settings_form($field) {
495
  $form = array();
496

    
497
  // Switch field.
498
  if (variable_get('ds_extras_switch_field') && $field['name'] == 'ds_switch_field') {
499
    $entity_type = $field['entity_type'];
500
    $bundle = $field['bundle'];
501
    $view_mode = $field['view_mode'];
502
    $settings = isset($field['formatter_settings']['vms']) ? $field['formatter_settings']['vms'] : array();
503
    $view_modes = ds_entity_view_modes($entity_type);
504

    
505
    $form['info'] = array(
506
      '#markup' => t('Enter a label for the link for the view modes you want to switch to.<br />Leave empty to hide link. They will be localized.'),
507
    );
508

    
509
    foreach ($view_modes as $key => $value) {
510

    
511
      $view_mode_settings = field_view_mode_settings($entity_type, $bundle);
512
      $visible = !empty($view_mode_settings[$key]['custom_settings']);
513

    
514
      if ($visible) {
515
        $form['vms'][$key] = array(
516
          '#type' => 'textfield',
517
          '#default_value' => isset($settings[$key]) ? $settings[$key] : '',
518
          '#size' => 20,
519
          '#title' => check_plain($value['label']),
520
        );
521
      }
522
    }
523
  }
524

    
525
  return $form;
526
}
527

    
528
/**
529
 * Submit callback after Field UI submission of a views display.
530
 */
531
function ds_extras_vd_field_ui_submit($form, &$form_state) {
532
  // Add the 'type' key to the extra title key so we can ditch the notice.
533
  $form_state['values']['fields']['title']['type'] = 'hidden';
534
}
535

    
536
/**
537
 * Submit callback: manage block regions.
538
 */
539
function ds_extras_block_submit($form, &$form_state) {
540

    
541
  // Create new region.
542
  if (!empty($form_state['values']['additional_settings']['region_to_block']['new_block_region'])) {
543

    
544
    // Get the entity_type, bundle and view mode.
545
    $entity_type = $form['#entity_type'];
546
    $bundle = $form['#bundle'];
547
    $view_mode = $form['#view_mode'];
548

    
549
    $block = array(
550
      'title' => $form_state['values']['additional_settings']['region_to_block']['new_block_region'],
551
      'info' => "{$entity_type}_{$bundle}_{$view_mode}",
552
    );
553

    
554
    $block_key = $form_state['values']['additional_settings']['region_to_block']['new_block_region_key'];
555
    $region_blocks = variable_get('ds_extras_region_blocks', array());
556
    $region_blocks[$block_key] = $block;
557
    variable_set('ds_extras_region_blocks', $region_blocks);
558
  }
559

    
560
  // Remove a region.
561
  if (isset($form_state['values']['additional_settings']['region_to_block']['remove_block_region'])) {
562
    $variable_set = FALSE;
563
    $region_blocks = variable_get('ds_extras_region_blocks', array());
564
    $remove = $form_state['values']['additional_settings']['region_to_block']['remove_block_region'];
565
    foreach ($remove as $key => $value) {
566
      if ($key === $value) {
567
        $variable_set = TRUE;
568
        if (module_exists('block')) {
569
          db_delete('block')
570
            ->condition('delta', $key)
571
            ->condition('module', 'ds_extras')
572
            ->execute();
573
        }
574
        unset($region_blocks[$key]);
575
      }
576
    }
577

    
578
    if ($variable_set) {
579
      variable_set('ds_extras_region_blocks', $region_blocks);
580
    }
581
  }
582
}
583

    
584
/**
585
 * Return unique region to block.
586
 */
587
function ds_extras_region_to_block_unique($name) {
588
  $region_blocks = variable_get('ds_extras_region_blocks', array());
589
  $value = strtr($name, array('-' => '_'));
590
  return isset($region_blocks[$value]) ? TRUE : FALSE;
591
}
592

    
593
/**
594
 * Helper function to show the page title options.
595
 */
596
function _ds_extras_page_title_options($settings, $entity_type) {
597

    
598
  $return['page_option_type'] = array(
599
    '#type' => 'select',
600
    '#title' => t('Page title'),
601
    '#options' => array(
602
      '0' => t('Show'),
603
      '1' => t('Hide'),
604
      '2' => t('Manually set'),
605
    ),
606
    '#default_value' => isset($settings['hide_page_title']) ? $settings['hide_page_title'] : FALSE,
607
    '#weight' => 100,
608
  );
609

    
610
  // Display Suite Views currently only supports hiding the page title.
611
  if ($entity_type == 'ds_views') {
612
    unset($return['page_option_type']['#options'][2]);
613
  }
614

    
615
  $contexts = ds_get_entity_context($entity_type);
616
  $rows = array();
617
  foreach ($contexts as $context) {
618
    foreach (ctools_context_get_converters('%' . check_plain($context->keyword) . ':', $context) as $keyword => $title) {
619
      $rows[] = array(
620
        check_plain($keyword),
621
        t('@identifier: @title', array('@title' => $title, '@identifier' => $context->identifier)),
622
      );
623
    }
624
  }
625

    
626
  $return['page_option_title'] = array(
627
    '#type' => 'textfield',
628
    '#title' => t('Title'),
629
    '#default_value' => isset($settings['page_option_title']) ? $settings['page_option_title'] : '',
630
    '#description' => t('The title, you may use substitutions in this title.'),
631
    '#weight' => 101,
632
    '#access' => $entity_type != 'ds_views',
633
    '#states' => array(
634
      'visible' => array(
635
        array(':input[name="page_option_type"]' => array('value' => '2')),
636
        array(':input[name="additional_settings[ds_page_title][ds_page_title_options][page_option_type]"]' => array('value' => '2')),
637
      ),
638
    ),
639
  );
640

    
641
  $header = array(t('Keyword'), t('Value'));
642
  $return['page_option_contexts'] = array(
643
    '#type' => 'fieldset',
644
    '#title' => t('Substitutions'),
645
    // Doesn't work because of http://drupal.org/node/1015798
646
    //'#collapsible' => TRUE,
647
    //'#collapsed' => TRUE,
648
    '#value' => theme('table', array('header' => $header, 'rows' => $rows)),
649
    '#weight' => 102,
650
    '#access' => $entity_type != 'ds_views',
651
    '#states' => array(
652
      'visible' => array(
653
        array(':input[name="page_option_type"]' => array('value' => '2')),
654
        array(':input[name="additional_settings[ds_page_title][ds_page_title_options][page_option_type]"]' => array('value' => '2')),
655
      ),
656
    ),
657
  );
658

    
659
  return $return;
660
}