Projet

Général

Profil

Paste
Télécharger (5,24 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ds / includes / ds.displays.inc @ d719f12f

1
<?php
2

    
3
/**
4
 * @file
5
 * Shows the overview screen with all links to entities.
6
 */
7

    
8
/**
9
 * Menu callback: Show the layout list.
10
 */
11
function ds_layout_list() {
12
  $build = array();
13

    
14
  // All entities.
15
  $rows = array();
16
  $entities = entity_get_info();
17

    
18
  // Change label of node content type to 'Content' and move to the top
19
  if (isset($entities['node'])) {
20
    $node_entity = $entities['node'];
21
    $node_entity['label'] = 'Content';
22
    unset($entities['node']);
23
    $entities = array_merge(array('node' => $node_entity), $entities);
24
  }
25

    
26
  if (isset($entities['comment'])) {
27
    $comment_entity = $entities['comment'];
28
    unset($entities['comment']);
29
    $entities['comment'] = $comment_entity;
30
  }
31

    
32
  foreach ($entities as $entity_type => $entity) {
33
    if ((isset($entity['fieldable']) && $entity['fieldable']) || isset($entity['ds_display'])) {
34

    
35
      $rows = array();
36
      foreach ($entity['bundles'] as $bundle_type => $bundle) {
37
        $row = array();
38

    
39
        $path = isset($bundle['admin']['real path']) ? $bundle['admin']['real path'] : (isset($bundle['admin']['path']) ? $bundle['admin']['path'] : '');
40
        if (empty($path)) {
41
          continue;
42
        }
43

    
44
        $row[] = check_plain($bundle['label']);
45
        $links = array(l(t('Manage display'), $path . '/display'));
46
        // Add Mangage Form link if this entity type is supported by ds_forms.
47
        if (module_exists('ds_forms') && _ds_forms_is_entity_type_supported($entity_type)) {
48
          $links[] = l(t('Manage form'), $path . '/fields');
49
        }
50
        $row[] = implode(' - ', $links);
51
        $rows[] = $row;
52
      }
53

    
54
      if (!empty($rows)) {
55
        $variables = array(
56
          'header' => array(array('data' => $entity['label']), array('data' => t('operations'), 'class' => 'ds-display-list-options')),
57
          'rows' => $rows,
58
        );
59
        $build['list_' . $entity_type] = array(
60
          '#markup' => theme('table', $variables)
61
        );
62

    
63
        $entity_rows = array();
64
        $rows = array();
65
      }
66
    }
67
  }
68
  drupal_add_css(drupal_get_path('module', 'ds') . '/css/ds.admin.css');
69

    
70
  return $build;
71
}
72

    
73
/**
74
 * Emergency page.
75
 */
76
function ds_emergency() {
77

    
78
  $form['ds_fields_error'] = array(
79
    '#type' => 'fieldset',
80
    '#title' => t('Fields error'),
81
  );
82

    
83
  $form['ds_fields_error']['ds_disable'] = array(
84
    '#type' => 'checkbox',
85
    '#title' => t('Disable attaching fields via Display Suite'),
86
    '#description' => t('In case you get an error after configuring a layout printing a message like "Fatal error: Unsupported operand types", you can temporarily disable adding fields from DS by toggling this checkbox. You probably are trying to render an node inside a node, for instance through a view, which is simply not possible. See <a href="http://drupal.org/node/1264386">http://drupal.org/node/1264386</a>.'),
87
    '#default_value' => variable_get('ds_disable', FALSE),
88
    '#weight' => 0,
89
  );
90

    
91
  $form['ds_fields_error']['submit'] = array(
92
    '#type' => 'submit',
93
    '#value' => t('Disable/enable field attach'),
94
    '#submit' => array('ds_emergency_fields_attach'),
95
    '#weight' => 1,
96
  );
97

    
98
  if (module_exists('ds_extras')) {
99
    $region_blocks = variable_get('ds_extras_region_blocks', array());
100
    if (!empty($region_blocks)) {
101

    
102
      $region_blocks_options = array();
103
      foreach ($region_blocks as $key => $info) {
104
        $region_blocks_options[$key] = $info['title'];
105
      }
106

    
107
      $form['region_to_block'] = array(
108
        '#type' => 'fieldset',
109
        '#title' => t('Block regions'),
110
      );
111

    
112
      $form['region_to_block']['remove_block_region'] = array(
113
        '#type' => 'checkboxes',
114
        '#options' => $region_blocks_options,
115
        '#description' => t('In case you renamed a content type, you will not see the configured block regions anymore, however the block on the block settings page is still available. On this screen you can remove orphaned block regions.'),
116
      );
117

    
118
      $form['region_to_block']['submit'] = array(
119
        '#type' => 'submit',
120
        '#value' => t('Remove block regions'),
121
        '#submit' => array('ds_emergency_region_to_block_submit'),
122
        '#weight' => 1,
123
      );
124
    }
125
  }
126

    
127
  return $form;
128
}
129

    
130
/**
131
 * Submit callback of fields error form.
132
 */
133
function ds_emergency_fields_attach($form, &$form_state) {
134
  variable_set('ds_disable', $form_state['values']['ds_disable']);
135
  drupal_set_message(t('The configuration options have been saved.'));
136
}
137

    
138
/**
139
 * Submit callback of region to block form.
140
 */
141
function ds_emergency_region_to_block_submit($form, &$form_state) {
142
  if (isset($form_state['values']['remove_block_region'])) {
143
    $variable_set = FALSE;
144
    $region_blocks = variable_get('ds_extras_region_blocks', array());
145
    $remove = $form_state['values']['remove_block_region'];
146
    foreach ($remove as $key => $value) {
147
      if ($value !== 0 && $key == $value) {
148
        $variable_set = TRUE;
149
        if (module_exists('block')) {
150
          db_delete('block')
151
            ->condition('delta', $key)
152
            ->condition('module', 'ds_extras')
153
            ->execute();
154
        }
155
        unset($region_blocks[$key]);
156
      }
157
    }
158

    
159
    if ($variable_set) {
160
      drupal_set_message(t('Block regions were removed.'));
161
      variable_set('ds_extras_region_blocks', $region_blocks);
162
    }
163
  }
164
  else {
165
    drupal_set_message(t('No block regions were removed.'));
166
  }
167
}