Projet

Général

Profil

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

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

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
//    'variables' => array('form' => NULL),
23
    'file' => 'includes/context.theme.inc',
24
  );
25
  $theme['ctools_context_item_row'] = array(
26
    'variables' => array('type' => NULL, 'form' => NULL, 'position' => NULL, 'count' => NULL, 'with_tr' => TRUE),
27
    'file' => 'includes/context.theme.inc',
28
  );
29

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

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

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

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

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

    
70
  $type_info = ctools_context_info($type);
71

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

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

    
99
    $output .= $rows;
100

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

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

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

    
127
  return $output;
128
}
129

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

    
144
  $contexts = ctools_context_load_contexts($object);
145

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

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

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

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

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

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

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

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

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

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

    
342
  return $output;
343
}
344