ui.theme.inc
10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php
/**
* @file Rules theme functions
*/
/**
* Themes a tree of rule elements in a draggable table.
*
* @ingroup themeable
*/
function theme_rules_elements($variables) {
$form = $variables['element'];
$form['#theme'] = 'table';
$form['#header'] = array(t('Elements'), t('Weight'), t('Operations'));
$form['#attributes']['id'] = 'rules-' . drupal_html_id($form['#caption']) . '-id';
foreach (element_children($form) as $element_id) {
$element = &$form[$element_id];
// Add special classes to be used for tabledrag.js.
$element['parent_id']['#attributes']['class'] = array('rules-parent-id');
$element['element_id']['#attributes']['class'] = array('rules-element-id');
$element['weight']['#attributes']['class'] = array('rules-element-weight');
$row = array();
$row[] = theme('indentation', array('size' => $element['#depth'])) . drupal_render($element['label']);
$row[] = drupal_render($element['weight']) . drupal_render($element['parent_id']) . drupal_render($element['element_id']);
$row[] = array('class' => 'rules-operations', 'data' => $element['operations']);
$row = array('data' => $row) + $element['#attributes'];
$row['class'][] = 'draggable';
if (!$element['#container']) {
$row['class'][] = 'tabledrag-leaf';
}
$form['#rows'][] = $row;
}
if (!empty($form['#rows'])) {
drupal_add_tabledrag($form['#attributes']['id'], 'match', 'parent', 'rules-parent-id', 'rules-parent-id', 'rules-element-id', TRUE, 10);
drupal_add_tabledrag($form['#attributes']['id'], 'order', 'sibling', 'rules-element-weight');
}
else {
$form['#rows'][] = array(array('data' => t('None'), 'colspan' => 3));
}
if (!empty($form['#add'])) {
$row = array();
$row[] = array('data' => $form['#add'], 'colspan' => 3);
$form['#rows'][] = array('data' => $row, 'class' => array('rules-elements-add'));
}
// Add a wrapping div.
return '<div class="rules-elements-table">' . drupal_render($form) . '</div>';
}
/**
* Themes the rules form for editing the used variables.
*
* @see RulesPluginUI::getVariableForm()
* @ingroup themeable
*/
function theme_rules_ui_variable_form($variables) {
$elements = $variables['element'];
$table['#theme'] = 'table';
$table['#header'] = array(t('Data type'), t('Label'), t('Machine name'), t('Usage'), array('data' => t('Weight'), 'class' => array('tabledrag-hide')));
$table['#attributes']['id'] = 'rules-' . drupal_html_id($elements['#title']) . '-id';
foreach (element_children($elements['items']) as $key) {
$element = &$elements['items'][$key];
// Add special classes to be used for tabledrag.js.
$element['weight']['#attributes']['class'] = array('rules-element-weight');
$row = array();
$row[] = array('data' => $element['type']);
$row[] = array('data' => $element['label']);
$row[] = array('data' => $element['name']);
$row[] = array('data' => $element['usage']);
$row[] = array('data' => $element['weight']);
$row = array('data' => $row) + $element['#attributes'];
$row['class'][] = 'draggable';
$table['#rows'][] = $row;
}
$elements['items']['#printed'] = TRUE;
if (!empty($table['#rows'])) {
drupal_add_tabledrag($table['#attributes']['id'], 'order', 'sibling', 'rules-element-weight');
}
// Theme it like a form item, but with the description above the content.
$attributes['class'][] = 'form-item';
$attributes['class'][] = 'rules-variables-form';
$output = '<div' . drupal_attributes($attributes) . '>' . "\n";
$output .= theme('form_element_label', $variables);
if (!empty($elements['#description'])) {
$output .= ' <div class="description">' . $elements['#description'] . "</div>\n";
}
$output .= ' ' . drupal_render($table) . "\n";
// Add in any further children elements.
foreach (element_children($elements, TRUE) as $key) {
$output .= drupal_render($elements[$key]);
}
$output .= "</div>\n";
return $output;
}
/**
* Themes a view of multiple configuration items.
* @ingroup themeable
*/
function theme_rules_content_group($variables) {
$element = $variables['element'];
$output = array();
foreach (element_children($element) as $key) {
$output[] = drupal_render($element[$key]);
}
$output = array_filter($output);
$heading = !empty($element['#caption']) ? "<span class='rules-content-heading'>" . $element['#caption'] . ': </span>' : '';
if (!empty($output)) {
$element['#attributes']['class'][] = 'rules-element-content-group';
return '<div' . drupal_attributes($element['#attributes']) . '>' . $heading . implode(', ', $output) . '</div>';
}
}
/**
* Themes the view of a single parameter configuration.
* @ingroup themeable
*/
function theme_rules_parameter_configuration($variables) {
$element = $variables['element'];
$content = drupal_render_children($element);
// Add the full content to the span's title, but don't use drupal_attributes
// for that as this would invoke check_plain() again.
$title = strip_tags($content);
$element['#attributes']['class'][] = 'rules-parameter-configuration';
$attributes = drupal_attributes($element['#attributes']) . " title='$title'";
$label_attributes['class'][] = 'rules-parameter-label';
if (!empty($element['#info']['description'])) {
$label_attributes['title'] = $element['#info']['description'];
}
$label_attributes = drupal_attributes($label_attributes);
$output = "<span $label_attributes>" . check_plain($element['#info']['label']) . ': </span>';
$output .= "<span $attributes>" . truncate_utf8($content, 30, TRUE, TRUE) . "</span>";
return $output;
}
/**
* Themes info about variables.
* @ingroup themeable
*/
function theme_rules_variable_view($variables) {
$element = $variables['element'];
$label_attributes['class'][] = 'rules-variable-label';
$label_attributes['title'] = '';
if (!empty($element['#info']['description'])) {
$label_attributes['title'] = $element['#info']['description'] . ' ';
}
$label_attributes['title'] .= t('Data type: !type', array('!type' => $element['#info']['type']));
$label_attributes = drupal_attributes($label_attributes);
$output = check_plain($element['#info']['label']);
$output .= ' (' . check_plain($element['#name']) . ')';
return "<span $label_attributes>" . $output . '</span>';
}
/**
* Themes help for using the data selector.
* @ingroup themeable
*/
function theme_rules_data_selector_help($variables) {
$variables_info = $variables['variables'];
$param_info = $variables['parameter'];
$render = array(
'#type' => 'fieldset',
'#title' => t('Data selectors'),
'#pre_render' => array(),
'#attributes' => array(),
);
// Make it manually collapsible as we cannot use #collapsible without the
// FAPI element processor.
$render['#attached']['js'][] = 'misc/collapse.js';
$render['#attributes']['class'][] = 'collapsible';
$render['#attributes']['class'][] = 'collapsed';
$render['table'] = array(
'#theme' => 'table',
'#header' => array(t('Selector'), t('Label'), t('Description')),
);
foreach (RulesData::matchingDataSelector($variables_info, $param_info) as $selector => $info) {
$info += array('label' => '', 'description' => '');
$render['table']['#rows'][] = array(check_plain($selector), check_plain(drupal_ucfirst($info['label'])), check_plain($info['description']));
}
return drupal_render($render);
}
/**
* Themes the rules log debug output.
* @ingroup themeable
*/
function theme_rules_log($variables) {
$element = $variables['element'];
drupal_add_css(drupal_get_path('module', 'rules') . '/ui/rules.ui.css');
// Add jquery ui core css and functions, which are needed for the icons.
drupal_add_library('system', 'ui');
drupal_add_js(drupal_get_path('module', 'rules') . '/ui/rules.debug.js');
$output = '<div class="rules-debug-log">';
$output .= '<h3 class="rules-debug-log-head">';
$output .= '<span class="rules-debug-open-main rules-debug-collapsible-link">';
$output .= '<span unselectable="on" class="ui-icon ui-icon-triangle-1-e rules-debug-icon-open"> </span>';
$output .= t('Rules evaluation log');
$output .= '</span>';
$output .= '</span>';
$output .= '<span class="rules-debug-open-all rules-debug-collapsible-link">-' . t('Open all') . '-<span>';
$output .= '</h3>';
$output .= '<div>';
$output .= $element['#children'];
$output .= '</div>';
$output .= '</div>';
return $output;
}
/**
* Theme rules debug log elements.
* @ingroup themeable
*/
function theme_rules_debug_element($variables) {
$output = '<div class="rules-debug-block">';
$output .= '<div class="rules-debug-log-head rules-debug-open rules-debug-collapsible-link">"';
$output .= '<span unselectable="on" class="ui-icon ui-icon-triangle-1-e rules-debug-icon-open"> </span>';
$output .= $variables['head'];
if (isset($variables['link'])) {
$output .= ' ' . $variables['link'];
}
$output .= '</div>';
$output .= $variables['log'];
$output .= '</div>';
return $output;
}
/**
* Themes rules autocomplete forms.
* @ingroup themeable
*/
function theme_rules_autocomplete($variables) {
$element = $variables['element'];
drupal_add_js(drupal_get_path('module', 'rules') . '/ui/rules.autocomplete.js');
drupal_add_library('system', 'ui.autocomplete');
drupal_add_library('system', 'ui.button');
$element['#attributes']['type'] = 'text';
element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength'));
_form_set_class($element, array('form-text', 'rules-autocomplete'));
$id = $element['#attributes']['id'];
$id_button = drupal_html_id($id . '-button');
$js_vars['rules_autocomplete'][$id] = array(
'inputId' => $id,
'source' => url($element['#autocomplete_path'], array('absolute' => TRUE)),
);
drupal_add_js($js_vars, 'setting');
$output = '<div class="rules-autocomplete">';
$output .= '<input' . drupal_attributes($element['#attributes']) . ' />';
$output .= '</div>';
return $output;
}
/**
* General theme function for displaying settings related help.
* @ingroup themeable
*/
function theme_rules_settings_help($variables) {
$text = $variables['text'];
$heading = $variables['heading'];
return "<p class=\"rules-settings-help\"><strong>$heading:</strong> $text</p>";
}