Projet

Général

Profil

Paste
Télécharger (10,2 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / rules / ui / ui.theme.inc @ 950416da

1
<?php
2

    
3
/**
4
 * @file
5
 * Rules theme functions.
6
 */
7

    
8
/**
9
 * Themes a tree of rule elements in a draggable table.
10
 *
11
 * @ingroup themeable
12
 */
13
function theme_rules_elements($variables) {
14
  $form = $variables['element'];
15
  $form['#theme'] = 'table';
16
  $form['#header'] = array(t('Elements'), t('Weight'), t('Operations'));
17
  $form['#attributes']['id'] = 'rules-' . drupal_html_id($form['#caption']) . '-id';
18

    
19
  foreach (element_children($form) as $element_id) {
20
    $element = &$form[$element_id];
21

    
22
    // Add special classes to be used for tabledrag.js.
23
    $element['parent_id']['#attributes']['class'] = array('rules-parent-id');
24
    $element['element_id']['#attributes']['class'] = array('rules-element-id');
25
    $element['weight']['#attributes']['class'] = array('rules-element-weight');
26

    
27
    $row = array();
28
    $row[] = theme('indentation', array('size' => $element['#depth'])) . drupal_render($element['label']);
29

    
30
    $row[] = drupal_render($element['weight']) . drupal_render($element['parent_id']) . drupal_render($element['element_id']);
31
    $row[] = array('class' => 'rules-operations', 'data' => $element['operations']);
32

    
33
    $row = array('data' => $row) + $element['#attributes'];
34
    $row['class'][] = 'draggable';
35
    if (!$element['#container']) {
36
      $row['class'][] = 'tabledrag-leaf';
37
    }
38
    $form['#rows'][] = $row;
39
  }
40
  if (!empty($form['#rows'])) {
41
    drupal_add_tabledrag($form['#attributes']['id'], 'match', 'parent', 'rules-parent-id', 'rules-parent-id', 'rules-element-id', TRUE, 10);
42
    drupal_add_tabledrag($form['#attributes']['id'], 'order', 'sibling', 'rules-element-weight');
43
  }
44
  else {
45
    $form['#rows'][] = array(array('data' => t('None'), 'colspan' => 3));
46
  }
47
  if (!empty($form['#add'])) {
48
    $row = array();
49
    $row[] = array('data' => $form['#add'], 'colspan' => 3);
50
    $form['#rows'][] = array('data' => $row, 'class' => array('rules-elements-add'));
51
  }
52

    
53
  // Add a wrapping div.
54
  return '<div class="rules-elements-table">' . drupal_render($form) . '</div>';
55
}
56

    
57
/**
58
 * Themes the rules form for editing the used variables.
59
 *
60
 * @see RulesPluginUI::getVariableForm()
61
 *
62
 * @ingroup themeable
63
 */
64
function theme_rules_ui_variable_form($variables) {
65
  $elements = $variables['element'];
66

    
67
  $table['#theme'] = 'table';
68
  $table['#header'] = array(
69
    t('Data type'),
70
    t('Label'),
71
    t('Machine name'),
72
    t('Usage'),
73
    array('data' => t('Weight'), 'class' => array('tabledrag-hide')),
74
  );
75
  $table['#attributes']['id'] = 'rules-' . drupal_html_id($elements['#title']) . '-id';
76

    
77
  foreach (element_children($elements['items']) as $key) {
78
    $element = &$elements['items'][$key];
79
    // Add special classes to be used for tabledrag.js.
80
    $element['weight']['#attributes']['class'] = array('rules-element-weight');
81

    
82
    $row = array();
83
    $row[] = array('data' => $element['type']);
84
    $row[] = array('data' => $element['label']);
85
    $row[] = array('data' => $element['name']);
86
    $row[] = array('data' => $element['usage']);
87
    $row[] = array('data' => $element['weight']);
88
    $row = array('data' => $row) + $element['#attributes'];
89
    $row['class'][] = 'draggable';
90
    $table['#rows'][] = $row;
91
  }
92
  $elements['items']['#printed'] = TRUE;
93
  if (!empty($table['#rows'])) {
94
    drupal_add_tabledrag($table['#attributes']['id'], 'order', 'sibling', 'rules-element-weight');
95
  }
96

    
97
  // Theme it like a form item, but with the description above the content.
98
  $attributes['class'][] = 'form-item';
99
  $attributes['class'][] = 'rules-variables-form';
100

    
101
  $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
102
  $output .= theme('form_element_label', $variables);
103
  if (!empty($elements['#description'])) {
104
    $output .= ' <div class="description">' . $elements['#description'] . "</div>\n";
105
  }
106
  $output .= ' ' . drupal_render($table) . "\n";
107
  // Add in any further children elements.
108
  foreach (element_children($elements, TRUE) as $key) {
109
    $output .= drupal_render($elements[$key]);
110
  }
111
  $output .= "</div>\n";
112
  return $output;
113
}
114

    
115
/**
116
 * Themes a view of multiple configuration items.
117
 *
118
 * @ingroup themeable
119
 */
120
function theme_rules_content_group($variables) {
121
  $element = $variables['element'];
122
  $output = array();
123
  foreach (element_children($element) as $key) {
124
    $output[] = drupal_render($element[$key]);
125
  }
126
  $output = array_filter($output);
127
  $heading = !empty($element['#caption']) ? "<span class='rules-content-heading'>" . $element['#caption'] . ': </span>' : '';
128
  if (!empty($output)) {
129
    $element['#attributes']['class'][] = 'rules-element-content-group';
130
    return '<div' . drupal_attributes($element['#attributes']) . '>' . $heading . implode(', ', $output) . '</div>';
131
  }
132
}
133

    
134
/**
135
 * Themes the view of a single parameter configuration.
136
 *
137
 * @ingroup themeable
138
 */
139
function theme_rules_parameter_configuration($variables) {
140
  $element = $variables['element'];
141
  $content = drupal_render_children($element);
142
  // Add the full content to the span's title, but don't use drupal_attributes
143
  // for that as this would invoke check_plain() again.
144
  $title = strip_tags($content);
145
  $element['#attributes']['class'][] = 'rules-parameter-configuration';
146
  $attributes = drupal_attributes($element['#attributes']) . " title='$title'";
147

    
148
  $label_attributes['class'][] = 'rules-parameter-label';
149
  if (!empty($element['#info']['description'])) {
150
    $label_attributes['title'] = $element['#info']['description'];
151
  }
152
  $label_attributes = drupal_attributes($label_attributes);
153

    
154
  $output = "<span $label_attributes>" . check_plain($element['#info']['label']) . ': </span>';
155
  $output .= "<span $attributes>" . truncate_utf8($content, 30, TRUE, TRUE) . "</span>";
156
  return $output;
157
}
158

    
159
/**
160
 * Themes info about variables.
161
 *
162
 * @ingroup themeable
163
 */
164
function theme_rules_variable_view($variables) {
165
  $element = $variables['element'];
166

    
167
  $label_attributes['class'][] = 'rules-variable-label';
168
  $label_attributes['title'] = '';
169
  if (!empty($element['#info']['description'])) {
170
    $label_attributes['title'] = $element['#info']['description'] . ' ';
171
  }
172
  $label_attributes['title'] .= t('Data type: !type', array('!type' => $element['#info']['type']));
173
  $label_attributes = drupal_attributes($label_attributes);
174

    
175
  $output = check_plain($element['#info']['label']);
176
  $output .= ' (' . check_plain($element['#name']) . ')';
177
  return "<span $label_attributes>" . $output . '</span>';
178
}
179

    
180
/**
181
 * Themes help for using the data selector.
182
 *
183
 * @ingroup themeable
184
 */
185
function theme_rules_data_selector_help($variables) {
186
  $variables_info = $variables['variables'];
187
  $param_info = $variables['parameter'];
188

    
189
  $render = array(
190
    '#type' => 'fieldset',
191
    '#title' => t('Data selectors'),
192
    '#pre_render' => array(),
193
    '#attributes' => array(),
194
  );
195
  // Make it manually collapsible as we cannot use #collapsible without the
196
  // FAPI element processor.
197
  $render['#attached']['js'][] = 'misc/collapse.js';
198
  $render['#attributes']['class'][] = 'collapsible';
199
  $render['#attributes']['class'][] = 'collapsed';
200

    
201
  $render['table'] = array(
202
    '#theme' => 'table',
203
    '#header' => array(t('Selector'), t('Label'), t('Description')),
204
  );
205
  foreach (RulesData::matchingDataSelector($variables_info, $param_info) as $selector => $info) {
206
    $info += array('label' => '', 'description' => '');
207
    $render['table']['#rows'][] = array(
208
      check_plain($selector),
209
      check_plain(drupal_ucfirst($info['label'])),
210
      check_plain($info['description']),
211
    );
212
  }
213
  return drupal_render($render);
214
}
215

    
216
/**
217
 * Themes the rules log debug output.
218
 *
219
 * @ingroup themeable
220
 */
221
function theme_rules_log($variables) {
222
  $element = $variables['element'];
223
  drupal_add_css(drupal_get_path('module', 'rules') . '/ui/rules.ui.css');
224
  // Add jquery ui core css and functions, which are needed for the icons.
225
  drupal_add_library('system', 'ui');
226
  drupal_add_js(drupal_get_path('module', 'rules') . '/ui/rules.debug.js');
227

    
228
  $output = '<div class="rules-debug-log">';
229

    
230
  $output .= '<h3 class="rules-debug-log-head">';
231
  $output .= '<span class="rules-debug-open-main rules-debug-collapsible-link">';
232
  $output .= '<span unselectable="on" class="ui-icon ui-icon-triangle-1-e rules-debug-icon-open">&nbsp;</span>';
233
  $output .= t('Rules evaluation log');
234
  $output .= '</span>';
235
  $output .= '</span>';
236
  $output .= '<span class="rules-debug-open-all rules-debug-collapsible-link">-' . t('Open all') . '-<span>';
237
  $output .= '</h3>';
238

    
239
  $output .= '<div>';
240
  $output .= $element['#children'];
241
  $output .= '</div>';
242
  $output .= '</div>';
243

    
244
  return $output;
245
}
246

    
247
/**
248
 * Theme rules debug log elements.
249
 *
250
 * @ingroup themeable
251
 */
252
function theme_rules_debug_element($variables) {
253
  $output = '<div class="rules-debug-block">';
254
  $output .= '<div class="rules-debug-log-head rules-debug-open rules-debug-collapsible-link">"';
255
  $output .= '<span unselectable="on" class="ui-icon ui-icon-triangle-1-e rules-debug-icon-open">&nbsp;</span>';
256
  $output .= $variables['head'];
257
  if (isset($variables['link'])) {
258
    $output .= ' ' . $variables['link'];
259
  }
260
  $output .= '</div>';
261
  $output .= $variables['log'];
262
  $output .= '</div>';
263
  return $output;
264
}
265

    
266
/**
267
 * Themes rules autocomplete forms.
268
 *
269
 * @ingroup themeable
270
 */
271
function theme_rules_autocomplete($variables) {
272
  $element = $variables['element'];
273
  drupal_add_js(drupal_get_path('module', 'rules') . '/ui/rules.autocomplete.js');
274
  drupal_add_library('system', 'ui.autocomplete');
275
  drupal_add_library('system', 'ui.button');
276

    
277
  $element['#attributes']['type'] = 'text';
278
  element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength'));
279
  _form_set_class($element, array('form-text', 'rules-autocomplete'));
280

    
281
  $id = $element['#attributes']['id'];
282
  $id_button = drupal_html_id($id . '-button');
283

    
284
  $js_vars['rules_autocomplete'][$id] = array(
285
    'inputId' => $id,
286
    'source' => url($element['#autocomplete_path'], array('absolute' => TRUE)),
287
  );
288
  drupal_add_js($js_vars, 'setting');
289

    
290
  $output = '<div class="rules-autocomplete">';
291
  $output .= '<input' . drupal_attributes($element['#attributes']) . ' />';
292
  $output .= '</div>';
293

    
294
  return $output;
295
}
296

    
297
/**
298
 * General theme function for displaying settings related help.
299
 *
300
 * @ingroup themeable
301
 */
302
function theme_rules_settings_help($variables) {
303
  $text = $variables['text'];
304
  $heading = $variables['heading'];
305
  return "<p class=\"rules-settings-help\"><strong>$heading:</strong> $text</p>";
306
}