Projet

Général

Profil

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

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

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. It does not work in combination with the reset layout.'),
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
      $form['ft']['fi-first-last'] = array(
419
        '#type' => 'checkbox',
420
        '#title' => t('Add first/last classes'),
421
        '#default_value' => isset($field_settings['fi-first-last']) ? $field_settings['fi-first-last'] : FALSE,
422
        '#states' => array(
423
          'visible' => array(
424
            ':input[name$="[ft][' . $wrapper_key . ']"]' => array('checked' => TRUE),
425
          ),
426
        ),
427
      );
428
    }
429
    if ($wrapper_key != 'lbw') {
430
      $form['ft'][$wrapper_key . '-def-at'] = array(
431
        '#type' => 'checkbox',
432
        '#title' => t('Add default attributes'),
433
        '#default_value' => isset($field_settings[$wrapper_key . '-def-at']) ? $field_settings[$wrapper_key . '-def-at'] : FALSE,
434
        '#suffix' => ($wrapper_key == 'ow') ? '' : '</div>',
435
        '#states' => array(
436
          'visible' => array(
437
            ':input[name$="[ft][' . $wrapper_key . ']"]' => array('checked' => TRUE),
438
          ),
439
        ),
440
      );
441
    }
442
    else {
443
      $form['ft'][$wrapper_key . '-def-at'] = array(
444
        '#markup' => '</div><div class="clearfix"></div>',
445
      );
446
    }
447

    
448
    // Default classes for outer wrapper.
449
    if ($wrapper_key == 'ow') {
450
      $form['ft'][$wrapper_key . '-def-cl'] = array(
451
        '#type' => 'checkbox',
452
        '#title' => t('Add default classes'),
453
        '#default_value' => isset($field_settings[$wrapper_key . '-def-cl']) ? $field_settings[$wrapper_key . '-def-cl'] : FALSE,
454
        '#suffix' => '</div>',
455
        '#states' => array(
456
          'visible' => array(
457
            ':input[name$="[ft][' . $wrapper_key . ']"]' => array('checked' => TRUE),
458
          ),
459
        ),
460
      );
461
    }
462
  }
463

    
464
  // Add suffix
465
  $form['ft']['suffix'] = array(
466
    '#type' => 'textfield',
467
    '#title' => t('Suffix'),
468
    '#size' => '100',
469
    '#description' => t('You can enter any html in here.'),
470
    '#default_value' => isset($field_settings['suffix']) ? $field_settings['suffix'] : '',
471
    '#prefix' => '<div class="field-prefix">',
472
    '#suffix' => '</div>',
473
  );
474

    
475
  // Another label needs some other stuff.
476
  unset($form['ft']['lb']['#description']);
477
  $form['ft']['lb']['#type'] = 'textfield';
478
  $form['ft']['lb']['#size'] = '10';
479
  $form['ft']['lb']['#attributes'] = array('class' => array('label-change'));
480
  $form['ft']['lb']['#default_value'] = isset($field_settings['lb']) ? $field_settings['lb'] : '';
481

    
482
  // Let other modules make modifications to the settings form as needed.
483
  drupal_alter('ds_field_theme_functions_settings_form_alter', $form, $field_settings);
484
}
485

    
486
/**
487
 * Implements hook_ds_field_format_summary().
488
 */
489
function ds_extras_ds_field_format_summary($field) {
490
  if (isset($field['formatter_settings'])) {
491
    foreach ($field['formatter_settings'] as $key => $value) {
492
      if (!empty($value)) {
493
        return t('Configured');
494
        break;
495
      }
496
    }
497
  }
498
  return t('Not configured');
499
}
500

    
501
/**
502
 * Implements hook_ds_field_settings_form().
503
 */
504
function ds_extras_ds_field_settings_form($field) {
505
  $form = array();
506

    
507
  // Switch field.
508
  if (variable_get('ds_extras_switch_field') && $field['name'] == 'ds_switch_field') {
509
    $entity_type = $field['entity_type'];
510
    $bundle = $field['bundle'];
511
    $view_mode = $field['view_mode'];
512
    $settings = isset($field['formatter_settings']['vms']) ? $field['formatter_settings']['vms'] : array();
513
    $view_modes = ds_entity_view_modes($entity_type);
514

    
515
    $form['info'] = array(
516
      '#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.'),
517
    );
518

    
519
    foreach ($view_modes as $key => $value) {
520

    
521
      $view_mode_settings = field_view_mode_settings($entity_type, $bundle);
522
      $visible = !empty($view_mode_settings[$key]['custom_settings']);
523

    
524
      if ($visible) {
525
        $form['vms'][$key] = array(
526
          '#type' => 'textfield',
527
          '#default_value' => isset($settings[$key]) ? $settings[$key] : '',
528
          '#size' => 20,
529
          '#title' => check_plain($value['label']),
530
        );
531
      }
532
    }
533
  }
534

    
535
  return $form;
536
}
537

    
538
/**
539
 * Submit callback after Field UI submission of a views display.
540
 */
541
function ds_extras_vd_field_ui_submit($form, &$form_state) {
542
  // Add the 'type' key to the extra title key so we can ditch the notice.
543
  $form_state['values']['fields']['title']['type'] = 'hidden';
544
}
545

    
546
/**
547
 * Submit callback: manage block regions.
548
 */
549
function ds_extras_block_submit($form, &$form_state) {
550

    
551
  // Create new region.
552
  if (!empty($form_state['values']['additional_settings']['region_to_block']['new_block_region'])) {
553

    
554
    // Get the entity_type, bundle and view mode.
555
    $entity_type = $form['#entity_type'];
556
    $bundle = $form['#bundle'];
557
    $view_mode = $form['#view_mode'];
558

    
559
    $block = array(
560
      'title' => $form_state['values']['additional_settings']['region_to_block']['new_block_region'],
561
      'info' => "{$entity_type}_{$bundle}_{$view_mode}",
562
    );
563

    
564
    $block_key = $form_state['values']['additional_settings']['region_to_block']['new_block_region_key'];
565
    $region_blocks = variable_get('ds_extras_region_blocks', array());
566
    $region_blocks[$block_key] = $block;
567
    variable_set('ds_extras_region_blocks', $region_blocks);
568
  }
569

    
570
  // Remove a region.
571
  if (isset($form_state['values']['additional_settings']['region_to_block']['remove_block_region'])) {
572
    $variable_set = FALSE;
573
    $region_blocks = variable_get('ds_extras_region_blocks', array());
574
    $remove = $form_state['values']['additional_settings']['region_to_block']['remove_block_region'];
575
    foreach ($remove as $key => $value) {
576
      if ($value != 0 && $key == $value) {
577
        $variable_set = TRUE;
578
        if (module_exists('block')) {
579
          db_delete('block')
580
            ->condition('delta', $key)
581
            ->condition('module', 'ds_extras')
582
            ->execute();
583
        }
584
        unset($region_blocks[$key]);
585
      }
586
    }
587

    
588
    if ($variable_set) {
589
      variable_set('ds_extras_region_blocks', $region_blocks);
590
    }
591
  }
592
}
593

    
594
/**
595
 * Return unique region to block.
596
 */
597
function ds_extras_region_to_block_unique($name) {
598
  $region_blocks = variable_get('ds_extras_region_blocks', array());
599
  $value = strtr($name, array('-' => '_'));
600
  return isset($region_blocks[$value]) ? TRUE : FALSE;
601
}
602

    
603
/**
604
 * Helper function to show the page title options.
605
 */
606
function _ds_extras_page_title_options($settings, $entity_type) {
607

    
608
  $return['page_option_type'] = array(
609
    '#type' => 'select',
610
    '#title' => t('Page title'),
611
    '#options' => array(
612
      '0' => t('Show'),
613
      '1' => t('Hide'),
614
      '2' => t('Manually set'),
615
    ),
616
    '#default_value' => isset($settings['hide_page_title']) ? $settings['hide_page_title'] : FALSE,
617
    '#weight' => 100,
618
  );
619

    
620
  // Display Suite Views currently only supports hiding the page title.
621
  if ($entity_type == 'ds_views') {
622
    unset($return['page_option_type']['#options'][2]);
623
  }
624

    
625
  $contexts = ds_get_entity_context($entity_type);
626
  $rows = array();
627
  foreach ($contexts as $context) {
628
    foreach (ctools_context_get_converters('%' . check_plain($context->keyword) . ':', $context) as $keyword => $title) {
629
      $rows[] = array(
630
        check_plain($keyword),
631
        t('@identifier: @title', array('@title' => $title, '@identifier' => $context->identifier)),
632
      );
633
    }
634
  }
635

    
636
  $return['page_option_title'] = array(
637
    '#type' => 'textfield',
638
    '#title' => t('Title'),
639
    '#default_value' => isset($settings['page_option_title']) ? $settings['page_option_title'] : '',
640
    '#description' => t('The title, you may use substitutions in this title.'),
641
    '#weight' => 101,
642
    '#access' => $entity_type != 'ds_views',
643
    '#states' => array(
644
      'visible' => array(
645
        array(':input[name="page_option_type"]' => array('value' => '2')),
646
        array(':input[name="additional_settings[ds_page_title][ds_page_title_options][page_option_type]"]' => array('value' => '2')),
647
      ),
648
    ),
649
  );
650

    
651
  $header = array(t('Keyword'), t('Value'));
652
  $return['page_option_contexts'] = array(
653
    '#type' => 'fieldset',
654
    '#title' => t('Substitutions'),
655
    // Doesn't work because of http://drupal.org/node/1015798
656
    //'#collapsible' => TRUE,
657
    //'#collapsed' => TRUE,
658
    '#value' => theme('table', array('header' => $header, 'rows' => $rows)),
659
    '#weight' => 102,
660
    '#access' => $entity_type != 'ds_views',
661
    '#states' => array(
662
      'visible' => array(
663
        array(':input[name="page_option_type"]' => array('value' => '2')),
664
        array(':input[name="additional_settings[ds_page_title][ds_page_title_options][page_option_type]"]' => array('value' => '2')),
665
      ),
666
    ),
667
  );
668

    
669
  return $return;
670
}