Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / includes / context.theme.inc @ 7e72b748

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains theme registry and theme implementations for the context tool.
6
 */
7

    
8
/**
9
 * Implements hook_theme()
10
 */
11
function ctools_context_theme(&$theme) {
12
  $theme['ctools_context_list'] = array(
13
    'variables' => array('object' => NULL),
14
    'file' => 'includes/context.theme.inc',
15
  );
16
  $theme['ctools_context_list_no_table'] = array(
17
    'variables' => array('object' => NULL),
18
    'file' => 'includes/context.theme.inc',
19
  );
20
  $theme['ctools_context_item_form'] = array(
21
    'render element' => 'form',
22
    'file' => 'includes/context.theme.inc',
23
  );
24
  $theme['ctools_context_item_row'] = array(
25
    'variables' => array('type' => NULL, 'form' => NULL, 'position' => NULL, 'count' => NULL, 'with_tr' => TRUE),
26
    'file' => 'includes/context.theme.inc',
27
  );
28

    
29
  // For the access plugin.
30
  $theme['ctools_access_admin_add'] = array(
31
    'render element' => 'form',
32
    'file' => 'includes/context-access-admin.inc',
33
  );
34
}
35

    
36
/**
37
 * Theme the form item for the context entry.
38
 */
39
function theme_ctools_context_item_row($vars) {
40
  $type = $vars['type'];
41
  $form = $vars['form'];
42
  $position = $vars['position'];
43
  $count = $vars['count'];
44
  $with_tr = $vars['with_tr'];
45
  $output = '<td class="title">&nbsp;' . render($form['title']) . '</td>';
46
  if (!empty($form['position'])) {
47
    $output .= '<td class="position">&nbsp;' . render($form['position']) . '</td>';
48
  }
49
  $output .= '<td class="operation">' . render($form['settings']);
50
  $output .= render($form['remove']) . '</td>';
51

    
52
  if ($with_tr) {
53
    $output = '<tr id="' . $type . '-row-' . $position . '" class="draggable ' . $type . '-row ' . ($count % 2 ? 'even' : 'odd') . '">' . $output . '</tr>';
54
  }
55
  return $output;
56
}
57

    
58
/**
59
 * Display the context item.
60
 */
61
function theme_ctools_context_item_form($vars) {
62
  $form = $vars['form'];
63

    
64
  $output    = '';
65
  $type      = $form['#ctools_context_type'];
66
  $module    = $form['#ctools_context_module'];
67
  $cache_key = $form['#cache_key'];
68

    
69
  $type_info = ctools_context_info($type);
70

    
71
  if (!empty($form[$type]) && empty($form['#only_buttons'])) {
72
    $count = 0;
73
    $rows = '';
74
    foreach (array_keys($form[$type]) as $id) {
75
      if (!is_numeric($id)) {
76
        continue;
77
      }
78
      $theme_vars = array();
79
      $theme_vars['type'] = $type;
80
      $theme_vars['form'] = $form[$type][$id];
81
      $theme_vars['position'] = $id;
82
      $theme_vars['count'] = $count++;
83
      $rows .= theme('ctools_context_item_row', $theme_vars);
84
    }
85

    
86
    $output .= '<table id="' . $type . '-table">';
87
    $output .= '<thead>';
88
    $output .= '<tr>';
89
    $output .= '<th class="title">' . $type_info['title'] . '</th>';
90
    if (!empty($type_info['sortable']) && $count) {
91
      $output .= '<th class="position">' . t('Weight') . '</th>';
92
    }
93
    $output .= '<th class="operation">' . t('Operation') . '</th>';
94
    $output .= '</tr>';
95
    $output .= '</thead>';
96
    $output .= '<tbody>';
97

    
98
    $output .= $rows;
99

    
100
    $output .= '</tbody>';
101
    $output .= '</table>';
102
  }
103

    
104
  if (!empty($form['buttons'])) {
105
    // Display the add context item.
106
    $row                      = array();
107
    $row[]                    = array('data' => render($form['buttons'][$type]['item']), 'class' => array('title'));
108
    $row[]                    = array('data' => render($form['buttons'][$type]['add']), 'class' => array('add'), 'width' => "60%");
109
    $output                  .= '<div class="buttons">';
110
    $output                  .= render($form['buttons'][$type]);
111
    $theme_vars               = array();
112
    $theme_vars['header']     = array();
113
    $theme_vars['rows']       = array($row);
114
    $theme_vars['attributes'] = array('id' => $type . '-add-table');
115
    $output                  .= theme('table', $theme_vars);
116
    $output                  .= '</div>';
117
  }
118
  if (!empty($form['description'])) {
119
    $output .= render($form['description']);
120
  }
121

    
122
  if (!empty($type_info['sortable'])) {
123
    drupal_add_tabledrag($type . '-table', 'order', 'sibling', 'drag-position');
124
  }
125

    
126
  return $output;
127
}
128

    
129
/**
130
 * Create a visible list of all the contexts available on an object.
131
 * Assumes arguments, relationships and context objects.
132
 *
133
 * Contexts must be preloaded.
134
 */
135
function theme_ctools_context_list($vars) {
136
  $object = $vars['object'];
137
  $header = $vars['header'];
138
  $description = (!empty($vars['description'])) ? $vars['description'] : NULL;
139
  $titles = array();
140
  $output = '';
141
  $count = 1;
142

    
143
  $contexts = ctools_context_load_contexts($object);
144

    
145
  // Describe 'built in' contexts.
146
  if (!empty($object->base_contexts)) {
147
    foreach ($object->base_contexts as $id => $context) {
148
      $output .= '<tr>';
149
      $output .= '<td valign="top"><em>' . t('Built in context') . '</em></td>';
150
      $desc = check_plain($context->identifier);
151
      if (isset($context->keyword)) {
152
        $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $context->keyword));
153
        foreach (ctools_context_get_converters('%' . $context->keyword . ':', $context) as $keyword => $title) {
154
          $desc .= '<br />' . t('@keyword --&gt; @title', array('@keyword' => $keyword, '@title' => $title));
155
        }
156
        $desc .= '</div>';
157

    
158
      }
159
      if (isset($context->description)) {
160
        $desc .= '<div class="description">' . filter_xss_admin($context->description) . '</div>';
161
      }
162
      $output .= '<td>' . $desc . '</td>';
163
      $output .= '</tr>';
164
      $titles[$id] = $context->identifier;
165
    }
166
  }
167

    
168
  // First, make a list of arguments. Arguments are pretty simple.
169
  if (!empty($object->arguments)) {
170
    foreach ($object->arguments as $argument) {
171
      $output .= '<tr>';
172
      $output .= '<td valign="top"><em>' . t('Argument @count', array('@count' => $count)) . '</em></td>';
173
      $desc = check_plain($argument['identifier']);
174
      if (isset($argument['keyword'])) {
175
        $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $argument['keyword']));
176
        if (isset($contexts[ctools_context_id($argument, 'argument')])) {
177
          foreach (ctools_context_get_converters('%' . $argument['keyword'] . ':', $contexts[ctools_context_id($argument, 'argument')]) as $keyword => $title) {
178
            $desc .= '<br />' . t('@keyword --&gt; @title', array('@keyword' => $keyword, '@title' => $title));
179
          }
180
        }
181
        $desc .= '</div>';
182
      }
183
      $output .= '<td>' . $desc . '</td>';
184
      $output .= '</tr>';
185
      $titles[ctools_context_id($argument, 'argument')] = $argument['identifier'];
186
      $count++;
187
    }
188
  }
189

    
190
  $count = 1;
191
  // Then, make a nice list of contexts.
192
  if (!empty($object->contexts)) {
193
    foreach ($object->contexts as $context) {
194
      $output .= '<tr>';
195
      $output .= '<td valign="top"><em>' . t('Context @count', array('@count' => $count)) . '</em></td>';
196
      $desc = check_plain($context['identifier']);
197
      if (isset($context['keyword'])) {
198
        $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $context['keyword']));
199
        foreach (ctools_context_get_converters('%' . $context['keyword'] . ':', $contexts[ctools_context_id($context, 'context')]) as $keyword => $title) {
200
          $desc .= '<br />' . t('@keyword --&gt; @title', array('@keyword' => $keyword, '@title' => $title));
201
        }
202
        $desc .= '</div>';
203
      }
204
      $output .= '<td>' . $desc . '</td>';
205
      $output .= '</tr>';
206
      $titles[ctools_context_id($context)] = $context['identifier'];
207
      $count++;
208
    }
209
  }
210

    
211
  // And relationships.
212
  if (!empty($object->relationships)) {
213
    foreach ($object->relationships as $relationship) {
214
      $output .= '<tr>';
215
      if (is_array($relationship['context'])) {
216
        $rtitles = array();
217
        foreach ($relationship['context'] as $cid) {
218
          $rtitles[$cid] = $titles[$cid];
219
        }
220
        $title = implode(' + ', $rtitles);
221
      }
222
      else {
223
        $title = $titles[$relationship['context']];
224
      }
225
      $output .= '<td valign="top"><em>' . t('From "@title"', array('@title' => $title)) . '</em></td>';
226
      $desc = check_plain($relationship['identifier']);
227
      if (isset($relationship['keyword'])) {
228
        $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $relationship['keyword']));
229
        foreach (ctools_context_get_converters('%' . $relationship['keyword'] . ':', $contexts[ctools_context_id($relationship, 'relationship')]) as $keyword => $title) {
230
          $desc .= '<br />' . t('@keyword --&gt; @title', array('@keyword' => $keyword, '@title' => $title));
231
        }
232
        $desc .= '</div>';
233
      }
234
      $output .= '<td>' . $desc . '</td>';
235
      $output .= '</tr>';
236
      $titles[ctools_context_id($relationship, 'relationship')] = $relationship['identifier'];
237
      $count++;
238
    }
239
  }
240

    
241
  $head = '';
242
  if ($header) {
243
    if ($description) {
244
      $header .= '<div class="description">' . $description . '</div>';
245
    }
246
    $head .= '<thead><tr>';
247
    $head .= '<th colspan="2">' . $header . '</th>';
248
    $head .= '</tr></thead>';
249
  }
250

    
251
  return $output ? "<table>$head<tbody>$output</tbody></table>\n" : "<table>$head</table>\n";
252
}
253

    
254
/**
255
 * The ctools_context_list() function but not in a table format because
256
 * tabledrag won't let us have tables within tables and still drag.
257
 */
258
function theme_ctools_context_list_no_table($vars) {
259
  $object = $vars['object'];
260
  ctools_add_css('context');
261
  $titles = array();
262
  $output = '';
263
  $count = 1;
264
  // Describe 'built in' contexts.
265
  if (!empty($object->base_contexts)) {
266
    foreach ($object->base_contexts as $id => $context) {
267
      $output .= '<div class="ctools-context-holder clearfix">';
268
      $output .= '<div class="ctools-context-title">' . t('Built in context') . '</div>';
269
      $desc = check_plain($context->identifier);
270
      if (isset($context->keyword)) {
271
        $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $context->keyword)) . '</div>';
272
      }
273
      if (isset($context->description)) {
274
        $desc .= '<div class="description">' . filter_xss_admin($context->description) . '</div>';
275
      }
276
      $output .= '<div class="ctools-context-content">' . $desc . '</div>';
277
      $output .= '</div>';
278
      $titles[$id] = $context->identifier;
279
      $count++;
280
    }
281
  }
282

    
283
  // First, make a list of arguments. Arguments are pretty simple.
284
  if (!empty($object->arguments)) {
285
    foreach ($object->arguments as $argument) {
286
      $output .= '<div class="ctools-context-holder clearfix">';
287
      $output .= '<div class="ctools-context-title">' . t('Argument @count', array('@count' => $count)) . '</div>';
288
      $desc = check_plain($argument['identifier']);
289
      if (isset($argument['keyword'])) {
290
        $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $argument['keyword'])) . '</div>';
291
      }
292
      $output .= '<div class="ctools-context-content">' . $desc . '</div>';
293
      $output .= '</div>';
294
      $titles[ctools_context_id($argument, 'argument')] = $argument['identifier'];
295
      $count++;
296
    }
297
  }
298
  $count = 1;
299
  // Then, make a nice list of contexts.
300
  if (!empty($object->contexts)) {
301
    foreach ($object->contexts as $context) {
302
      $output .= '<div class="ctools-context-holder clearfix">';
303
      $output .= '<div class="ctools-context-title">' . t('Context @count', array('@count' => $count)) . '</div>';
304
      $desc = check_plain($context['identifier']);
305
      if (isset($context['keyword'])) {
306
        $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $context['keyword'])) . '</div>';
307
      }
308
      $output .= '<div class="ctools-context-content">' . $desc . '</div>';
309
      $output .= '</div>';
310
      $titles[ctools_context_id($context)] = $context['identifier'];
311
      $count++;
312
    }
313
  }
314
  // And relationships.
315
  if (!empty($object->relationships)) {
316
    foreach ($object->relationships as $relationship) {
317
      $output .= '<div class="ctools-context-holder clearfix">';
318
      if (is_array($relationship['context'])) {
319
        $rtitles = array();
320
        foreach ($relationship['context'] as $cid) {
321
          $rtitles[$cid] = $titles[$cid];
322
        }
323
        $title = implode(' + ', $rtitles);
324
      }
325
      else {
326
        $title = $titles[$relationship['context']];
327
      }
328

    
329
      $output .= '<div class="ctools-context-title">' . t('From "@title"', array('@title' => $title)) . '</div>';
330
      $desc = check_plain($relationship['identifier']);
331
      if (isset($relationship['keyword'])) {
332
        $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $relationship['keyword'])) . '</div>';
333
      }
334
      $output .= '<div class="ctools-context-content">' . $desc . '</div>';
335
      $output .= '</div>';
336
      $titles[ctools_context_id($relationship, 'relationship')] = $relationship['identifier'];
337
      $count++;
338
    }
339
  }
340

    
341
  return $output;
342
}