1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * Contains theme registry and theme implementations for the context tool. |
---|
6 | */ |
---|
7 | |
---|
8 | /** |
---|
9 | * Implementation of hook_theme() |
---|
10 | */ |
---|
11 | function ctools_context_theme(&$theme) { |
---|
12 | $theme['ctools_context_list'] = array( |
---|
13 | 'arguments' => array('object'), |
---|
14 | 'file' => 'includes/context.theme.inc', |
---|
15 | ); |
---|
16 | $theme['ctools_context_list_no_table'] = array( |
---|
17 | 'arguments' => array('object'), |
---|
18 | 'file' => 'includes/context.theme.inc', |
---|
19 | ); |
---|
20 | $theme['ctools_context_item_form'] = array( |
---|
21 | 'arguments' => array('form'), |
---|
22 | 'file' => 'includes/context.theme.inc', |
---|
23 | ); |
---|
24 | $theme['ctools_context_item_row'] = array( |
---|
25 | 'arguments' => array('type', 'form', 'position', 'count', 'with_tr' => TRUE), |
---|
26 | 'file' => 'includes/context.theme.inc', |
---|
27 | ); |
---|
28 | |
---|
29 | // For the access plugin |
---|
30 | $theme['ctools_access_admin_add'] = array( |
---|
31 | 'arguments' => array('form'), |
---|
32 | 'file' => 'includes/context-admin.inc', |
---|
33 | ); |
---|
34 | } |
---|
35 | |
---|
36 | /** |
---|
37 | * Theme the form item for the context entry. |
---|
38 | */ |
---|
39 | function theme_ctools_context_item_row($type, $form, $position, $count, $with_tr = TRUE) { |
---|
40 | $output = '<td class="title"> ' . drupal_render($form['title']) . '</td>'; |
---|
41 | if (!empty($form['position'])) { |
---|
42 | $output .= '<td class="position"> ' . drupal_render($form['position']) . '</td>'; |
---|
43 | } |
---|
44 | $output .= '<td class="operation">' . drupal_render($form['settings']); |
---|
45 | $output .= drupal_render($form['remove']) . '</td>'; |
---|
46 | |
---|
47 | if ($with_tr) { |
---|
48 | $output = '<tr id="' . $type . '-row-' . $position . '" class="draggable ' . $type . '-row ' . ($count % 2 ? 'even' : 'odd') . '">' . $output . '</tr>'; |
---|
49 | } |
---|
50 | return $output; |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * Display the context item. |
---|
55 | */ |
---|
56 | function theme_ctools_context_item_form($form) { |
---|
57 | $output = ''; |
---|
58 | $type = $form['#ctools_context_type']; |
---|
59 | $module = $form['#ctools_context_module']; |
---|
60 | $name = $form['#object_name']; |
---|
61 | |
---|
62 | $type_info = ctools_context_info($type); |
---|
63 | |
---|
64 | if (!empty($form[$type]) && empty($form['#only_buttons'])) { |
---|
65 | $count = 0; |
---|
66 | $rows = ''; |
---|
67 | foreach (array_keys($form[$type]) as $id) { |
---|
68 | if (!is_numeric($id)) { |
---|
69 | continue; |
---|
70 | } |
---|
71 | $rows .= theme('ctools_context_item_row', $type, $form[$type][$id], $id, $count++); |
---|
72 | } |
---|
73 | |
---|
74 | $output .= '<table id="' . $type . '-table">'; |
---|
75 | $output .= '<thead>'; |
---|
76 | $output .= '<tr>'; |
---|
77 | $output .= '<th class="title">' . $type_info['title'] . '</th>'; |
---|
78 | if (!empty($type_info['sortable']) && $count) { |
---|
79 | $output .= '<th class="position">' . t('Weight') . '</th>'; |
---|
80 | } |
---|
81 | $output .= '<th class="operation">' . t('Operation') . '</th>'; |
---|
82 | $output .= '</tr>'; |
---|
83 | $output .= '</thead>'; |
---|
84 | $output .= '<tbody>'; |
---|
85 | |
---|
86 | $output .= $rows; |
---|
87 | |
---|
88 | $output .= '</tbody>'; |
---|
89 | $output .= '</table>'; |
---|
90 | } |
---|
91 | |
---|
92 | if (!empty($form['buttons'])) { |
---|
93 | // Display the add context item. |
---|
94 | $row = array(); |
---|
95 | $row[] = array('data' => drupal_render($form['buttons'][$type]['item']), 'class' => 'title'); |
---|
96 | $row[] = array('data' => drupal_render($form['buttons'][$type]['add']), 'class' => 'add', 'width' => "60%"); |
---|
97 | $output .= '<div class="buttons">'; |
---|
98 | $output .= drupal_render($form['buttons'][$type]); |
---|
99 | $output .= theme('table', array(), array($row), array('id' => $type . '-add-table')); |
---|
100 | $output .= '</div>'; |
---|
101 | } |
---|
102 | if (!empty($form['description'])) { |
---|
103 | $output .= drupal_render($form['description']); |
---|
104 | } |
---|
105 | |
---|
106 | if (!empty($type_info['sortable'])) { |
---|
107 | drupal_add_tabledrag($type . '-table', 'order', 'sibling', 'drag-position'); |
---|
108 | } |
---|
109 | |
---|
110 | return $output; |
---|
111 | } |
---|
112 | |
---|
113 | /** |
---|
114 | * Create a visible list of all the contexts available on an object. |
---|
115 | * Assumes arguments, relationships and context objects. |
---|
116 | * |
---|
117 | * Contexts must be preloaded. |
---|
118 | */ |
---|
119 | function theme_ctools_context_list($object, $header = '', $description = '') { |
---|
120 | $titles = array(); |
---|
121 | $output = ''; |
---|
122 | $count = 1; |
---|
123 | |
---|
124 | $contexts = ctools_context_load_contexts($object); |
---|
125 | |
---|
126 | // Describe 'built in' contexts. |
---|
127 | if (!empty($object->base_contexts)) { |
---|
128 | foreach ($object->base_contexts as $id => $context) { |
---|
129 | $output .= '<tr>'; |
---|
130 | $output .= '<td valign="top"><em>' . t('Built in context') . '</em></td>'; |
---|
131 | $desc = check_plain($context->identifier); |
---|
132 | if (isset($context->keyword)) { |
---|
133 | $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $context->keyword)); |
---|
134 | foreach (ctools_context_get_converters('%' . $context->keyword . ':', $context) as $keyword => $title) { |
---|
135 | $desc .= '<br />' . t('@keyword --> @title', array('@keyword' => $keyword, '@title' => $title)); |
---|
136 | } |
---|
137 | $desc .= '</div>'; |
---|
138 | |
---|
139 | } |
---|
140 | if (isset($context->description)) { |
---|
141 | $desc .= '<div class="description">' . filter_xss_admin($context->description) . '</div>'; |
---|
142 | } |
---|
143 | $output .= '<td>' . $desc . '</td>'; |
---|
144 | $output .= '</tr>'; |
---|
145 | $titles[$id] = $context->identifier; |
---|
146 | } |
---|
147 | } |
---|
148 | |
---|
149 | // First, make a list of arguments. Arguments are pretty simple. |
---|
150 | if (!empty($object->arguments)) { |
---|
151 | foreach ($object->arguments as $argument) { |
---|
152 | $output .= '<tr>'; |
---|
153 | $output .= '<td valign="top"><em>' . t('Argument @count', array('@count' => $count)) . '</em></td>'; |
---|
154 | $desc = check_plain($argument['identifier']); |
---|
155 | if (isset($argument['keyword'])) { |
---|
156 | $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $argument['keyword'])); |
---|
157 | if (isset($contexts[ctools_context_id($argument, 'argument')])) { |
---|
158 | foreach (ctools_context_get_converters('%' . $argument['keyword'] . ':', $contexts[ctools_context_id($argument, 'argument')]) as $keyword => $title) { |
---|
159 | $desc .= '<br />' . t('@keyword --> @title', array('@keyword' => $keyword, '@title' => $title)); |
---|
160 | } |
---|
161 | } |
---|
162 | $desc .= '</div>'; |
---|
163 | } |
---|
164 | $output .= '<td>' . $desc . '</td>'; |
---|
165 | $output .= '</tr>'; |
---|
166 | $titles[ctools_context_id($argument, 'argument')] = $argument['identifier']; |
---|
167 | $count++; |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | $count = 1; |
---|
172 | // Then, make a nice list of contexts. |
---|
173 | if (!empty($object->contexts)) { |
---|
174 | foreach ($object->contexts as $context) { |
---|
175 | $output .= '<tr>'; |
---|
176 | $output .= '<td valign="top"><em>' . t('Context @count', array('@count' => $count)) . '</em></td>'; |
---|
177 | $desc = check_plain($context['identifier']); |
---|
178 | if (isset($context['keyword'])) { |
---|
179 | $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $context['keyword'])); |
---|
180 | foreach (ctools_context_get_converters('%' . $context['keyword'] . ':', $contexts[ctools_context_id($context, 'context')]) as $keyword => $title) { |
---|
181 | $desc .= '<br />' . t('@keyword --> @title', array('@keyword' => $keyword, '@title' => $title)); |
---|
182 | } |
---|
183 | $desc .= '</div>'; |
---|
184 | } |
---|
185 | $output .= '<td>' . $desc . '</td>'; |
---|
186 | $output .= '</tr>'; |
---|
187 | $titles[ctools_context_id($context)] = $context['identifier']; |
---|
188 | $count++; |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | // And relationships |
---|
193 | if (!empty($object->relationships)) { |
---|
194 | foreach ($object->relationships as $relationship) { |
---|
195 | $output .= '<tr>'; |
---|
196 | if (is_array($relationship['context'])) { |
---|
197 | $rtitles = array(); |
---|
198 | foreach ($relationship['context'] as $cid) { |
---|
199 | $rtitles[$cid] = $titles[$cid]; |
---|
200 | } |
---|
201 | $title = implode(' + ', $rtitles); |
---|
202 | } |
---|
203 | else { |
---|
204 | $title = $titles[$relationship['context']]; |
---|
205 | } |
---|
206 | $output .= '<td valign="top"><em>' . t('From "@title"', array('@title' => $title)) . '</em></td>'; |
---|
207 | $desc = check_plain($relationship['identifier']); |
---|
208 | if (isset($relationship['keyword'])) { |
---|
209 | $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $relationship['keyword'])); |
---|
210 | foreach (ctools_context_get_converters('%' . $relationship['keyword'] . ':', $contexts[ctools_context_id($relationship, 'relationship')]) as $keyword => $title) { |
---|
211 | $desc .= '<br />' . t('@keyword --> @title', array('@keyword' => $keyword, '@title' => $title)); |
---|
212 | } |
---|
213 | $desc .= '</div>'; |
---|
214 | } |
---|
215 | $output .= '<td>' . $desc . '</td>'; |
---|
216 | $output .= '</tr>'; |
---|
217 | $titles[ctools_context_id($relationship, 'relationship')] = $relationship['identifier']; |
---|
218 | $count++; |
---|
219 | } |
---|
220 | } |
---|
221 | |
---|
222 | $head = ''; |
---|
223 | if ($header) { |
---|
224 | if ($description) { |
---|
225 | $header .= '<div class="description">' . $description . '</div>'; |
---|
226 | } |
---|
227 | $head .= '<thead><tr>'; |
---|
228 | $head .= '<th colspan="2">' . $header . '</th>'; |
---|
229 | $head .= '</tr></thead>'; |
---|
230 | } |
---|
231 | |
---|
232 | return $output ? "<table>$head<tbody>$output</tbody></table>\n" : "<table>$head</table>\n"; |
---|
233 | } |
---|
234 | |
---|
235 | /** |
---|
236 | * ctools_context_list() but not in a table format because tabledrag |
---|
237 | * won't let us have tables within tables and still drag. |
---|
238 | */ |
---|
239 | function theme_ctools_context_list_no_table($object) { |
---|
240 | ctools_add_css('context'); |
---|
241 | $titles = array(); |
---|
242 | $output = ''; |
---|
243 | $count = 1; |
---|
244 | // Describe 'built in' contexts. |
---|
245 | if (!empty($object->base_contexts)) { |
---|
246 | foreach ($object->base_contexts as $id => $context) { |
---|
247 | $output .= '<div class="ctools-context-holder clear-block">'; |
---|
248 | $output .= '<div class="ctools-context-title">' . t('Built in context') . '</div>'; |
---|
249 | $desc = check_plain($context->identifier); |
---|
250 | if (isset($context->keyword)) { |
---|
251 | $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $context->keyword)) . '</div>'; |
---|
252 | } |
---|
253 | if (isset($context->description)) { |
---|
254 | $desc .= '<div class="description">' . filter_xss_admin($context->description) . '</div>'; |
---|
255 | } |
---|
256 | $output .= '<div class="ctools-context-content">' . $desc . '</div>'; |
---|
257 | $output .= '</div>'; |
---|
258 | $titles[$id] = $context->identifier; |
---|
259 | $count++; |
---|
260 | } |
---|
261 | } |
---|
262 | |
---|
263 | // First, make a list of arguments. Arguments are pretty simple. |
---|
264 | if (!empty($object->arguments)) { |
---|
265 | foreach ($object->arguments as $argument) { |
---|
266 | $output .= '<div class="ctools-context-holder clear-block">'; |
---|
267 | $output .= '<div class="ctools-context-title">' . t('Argument @count', array('@count' => $count)) . '</div>'; |
---|
268 | $desc = check_plain($argument['identifier']); |
---|
269 | if (isset($argument['keyword'])) { |
---|
270 | $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $argument['keyword'])) . '</div>'; |
---|
271 | } |
---|
272 | $output .= '<div class="ctools-context-content">' . $desc . '</div>'; |
---|
273 | $output .= '</div>'; |
---|
274 | $titles[ctools_context_id($argument, 'argument')] = $argument['identifier']; |
---|
275 | $count++; |
---|
276 | } |
---|
277 | } |
---|
278 | $count = 1; |
---|
279 | // Then, make a nice list of contexts. |
---|
280 | if (!empty($object->contexts)) { |
---|
281 | foreach ($object->contexts as $context) { |
---|
282 | $output .= '<div class="ctools-context-holder clear-block">'; |
---|
283 | $output .= '<div class="ctools-context-title">' . t('Context @count', array('@count' => $count)) . '</div>'; |
---|
284 | $desc = check_plain($context['identifier']); |
---|
285 | if (isset($context['keyword'])) { |
---|
286 | $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $context['keyword'])) . '</div>'; |
---|
287 | } |
---|
288 | $output .= '<div class="ctools-context-content">' . $desc . '</div>'; |
---|
289 | $output .= '</div>'; |
---|
290 | $titles[ctools_context_id($context)] = $context['identifier']; |
---|
291 | $count++; |
---|
292 | } |
---|
293 | } |
---|
294 | // And relationships |
---|
295 | if (!empty($object->relationships)) { |
---|
296 | foreach ($object->relationships as $relationship) { |
---|
297 | $output .= '<div class="ctools-context-holder clear-block">'; |
---|
298 | if (is_array($relationship['context'])) { |
---|
299 | $rtitles = array(); |
---|
300 | foreach ($relationship['context'] as $cid) { |
---|
301 | $rtitles[$cid] = $titles[$cid]; |
---|
302 | } |
---|
303 | $title = implode(' + ', $rtitles); |
---|
304 | } |
---|
305 | else { |
---|
306 | $title = $titles[$relationship['context']]; |
---|
307 | } |
---|
308 | |
---|
309 | $output .= '<div class="ctools-context-title">' . t('From "@title"', array('@title' => $title)) . '</div>'; |
---|
310 | $desc = check_plain($relationship['identifier']); |
---|
311 | if (isset($relationship['keyword'])) { |
---|
312 | $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $relationship['keyword'])) . '</div>'; |
---|
313 | } |
---|
314 | $output .= '<div class="ctools-context-content">' . $desc . '</div>'; |
---|
315 | $output .= '</div>'; |
---|
316 | $titles[ctools_context_id($relationship, 'relationship')] = $relationship['identifier']; |
---|
317 | $count++; |
---|
318 | } |
---|
319 | } |
---|
320 | |
---|
321 | return $output; |
---|
322 | } |
---|
323 | |
---|