Projet

Général

Profil

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

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

1
<?php
2

    
3
/**
4
 * @file Rules theme functions
5
 */
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
 * @ingroup themeable
62
 */
63
function theme_rules_ui_variable_form($variables) {
64
  $elements = $variables['element'];
65

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

    
70
  foreach (element_children($elements['items']) as $key) {
71
    $element = &$elements['items'][$key];
72
    // Add special classes to be used for tabledrag.js.
73
    $element['weight']['#attributes']['class'] = array('rules-element-weight');
74

    
75
    $row = array();
76
    $row[] = array('data' => $element['type']);
77
    $row[] = array('data' => $element['label']);
78
    $row[] = array('data' => $element['name']);
79
    $row[] = array('data' => $element['usage']);
80
    $row[] = array('data' => $element['weight']);
81
    $row = array('data' => $row) + $element['#attributes'];
82
    $row['class'][] = 'draggable';
83
    $table['#rows'][] = $row;
84
  }
85
  $elements['items']['#printed'] = TRUE;
86
  if (!empty($table['#rows'])) {
87
    drupal_add_tabledrag($table['#attributes']['id'], 'order', 'sibling', 'rules-element-weight');
88
  }
89

    
90
  // Theme it like a form item, but with the description above the content.
91
  $attributes['class'][] = 'form-item';
92
  $attributes['class'][] = 'rules-variables-form';
93

    
94
  $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
95
  $output .= theme('form_element_label', $variables);
96
  if (!empty($elements['#description'])) {
97
    $output .= ' <div class="description">' . $elements['#description'] . "</div>\n";
98
  }
99
  $output .= ' ' . drupal_render($table) . "\n";
100
  // Add in any further children elements.
101
  foreach (element_children($elements, TRUE) as $key) {
102
    $output .= drupal_render($elements[$key]);
103
  }
104
  $output .= "</div>\n";
105
  return $output;
106
}
107

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

    
126
/**
127
 * Themes the view of a single parameter configuration.
128
 * @ingroup themeable
129
 */
130
function theme_rules_parameter_configuration($variables) {
131
  $element = $variables['element'];
132
  $content = drupal_render_children($element);
133
  // Add the full content to the span's title, but don't use drupal_attributes
134
  // for that as this would invoke check_plain() again.
135
  $title = strip_tags($content);
136
  $element['#attributes']['class'][] = 'rules-parameter-configuration';
137
  $attributes = drupal_attributes($element['#attributes']) . " title='$title'";
138

    
139
  $label_attributes['class'][] = 'rules-parameter-label';
140
  if (!empty($element['#info']['description'])) {
141
    $label_attributes['title'] = $element['#info']['description'];
142
  }
143
  $label_attributes = drupal_attributes($label_attributes);
144

    
145
  $output = "<span $label_attributes>" . check_plain($element['#info']['label']) . ': </span>';
146
  $output .= "<span $attributes>" . truncate_utf8($content, 30, TRUE, TRUE) . "</span>";
147
  return $output;
148
}
149

    
150
/**
151
 * Themes info about variables.
152
 * @ingroup themeable
153
 */
154
function theme_rules_variable_view($variables) {
155
  $element = $variables['element'];
156

    
157
  $label_attributes['class'][] = 'rules-variable-label';
158
  $label_attributes['title'] = '';
159
  if (!empty($element['#info']['description'])) {
160
    $label_attributes['title'] = $element['#info']['description'] . ' ';
161
  }
162
  $label_attributes['title'] .= t('Data type: !type', array('!type' => $element['#info']['type']));
163
  $label_attributes = drupal_attributes($label_attributes);
164

    
165
  $output = check_plain($element['#info']['label']);
166
  $output .= ' (' . check_plain($element['#name']) . ')';
167
  return "<span $label_attributes>" . $output . '</span>';
168
}
169

    
170
/**
171
 * Themes help for using the data selector.
172
 * @ingroup themeable
173
 */
174
function theme_rules_data_selector_help($variables) {
175
  $variables_info = $variables['variables'];
176
  $param_info = $variables['parameter'];
177

    
178
  $render = array(
179
    '#type' => 'fieldset',
180
    '#title' => t('Data selectors'),
181
    '#pre_render' => array(),
182
    '#attributes' => array(),
183
  );
184
  // Make it manually collapsible as we cannot use #collapsible without the
185
  // FAPI element processor.
186
  $render['#attached']['js'][] = 'misc/collapse.js';
187
  $render['#attributes']['class'][] = 'collapsible';
188
  $render['#attributes']['class'][] = 'collapsed';
189

    
190
  $render['table'] = array(
191
    '#theme' => 'table',
192
    '#header' => array(t('Selector'), t('Label'), t('Description')),
193
  );
194
  foreach (RulesData::matchingDataSelector($variables_info, $param_info) as $selector => $info) {
195
    $info += array('label' => '', 'description' => '');
196
    $render['table']['#rows'][] = array(check_plain($selector), check_plain(drupal_ucfirst($info['label'])), check_plain($info['description']));
197
  }
198
  return drupal_render($render);
199
}
200

    
201
/**
202
 * Themes the rules log debug output.
203
 * @ingroup themeable
204
 */
205
function theme_rules_log($variables) {
206
  $element = $variables['element'];
207
  drupal_add_css(drupal_get_path('module', 'rules') . '/ui/rules.ui.css');
208
  // Add jquery ui core css and functions, which are needed for the icons.
209
  drupal_add_library('system', 'ui');
210
  drupal_add_js(drupal_get_path('module', 'rules') . '/ui/rules.debug.js');
211

    
212
  $output = '<div class="rules-debug-log">';
213

    
214
  $output .= '<h3 class="rules-debug-log-head">';
215
  $output .= '<span class="rules-debug-open-main rules-debug-collapsible-link">';
216
  $output .= '<span unselectable="on" class="ui-icon ui-icon-triangle-1-e rules-debug-icon-open">&nbsp;</span>';
217
  $output .= t('Rules evaluation log');
218
  $output .= '</span>';
219
  $output .= '</span>';
220
  $output .= '<span class="rules-debug-open-all rules-debug-collapsible-link">-' . t('Open all') . '-<span>';
221
  $output .= '</h3>';
222

    
223
  $output .= '<div>';
224
  $output .= $element['#children'];
225
  $output .= '</div>';
226
  $output .= '</div>';
227

    
228
  return $output;
229
}
230

    
231
/**
232
 * Theme rules debug log elements.
233
 * @ingroup themeable
234
 */
235
function theme_rules_debug_element($variables) {
236
  $output = '<div class="rules-debug-block">';
237
  $output .= '<div class="rules-debug-log-head rules-debug-open rules-debug-collapsible-link">"';
238
  $output .= '<span unselectable="on" class="ui-icon ui-icon-triangle-1-e rules-debug-icon-open">&nbsp;</span>';
239
  $output .= $variables['head'];
240
  if (isset($variables['link'])) {
241
    $output .= ' ' . $variables['link'];
242
  }
243
  $output .= '</div>';
244
  $output .= $variables['log'];
245
  $output .= '</div>';
246
  return $output;
247
}
248

    
249
/**
250
 * Themes rules autocomplete forms.
251
 * @ingroup themeable
252
 */
253
function theme_rules_autocomplete($variables) {
254
  $element = $variables['element'];
255
  drupal_add_js(drupal_get_path('module', 'rules') . '/ui/rules.autocomplete.js');
256
  drupal_add_library('system', 'ui.autocomplete');
257
  drupal_add_library('system', 'ui.button');
258

    
259
  $element['#attributes']['type'] = 'text';
260
  element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength'));
261
  _form_set_class($element, array('form-text', 'rules-autocomplete'));
262

    
263
  $id = $element['#attributes']['id'];
264
  $id_button = drupal_html_id($id . '-button');
265

    
266
  $js_vars['rules_autocomplete'][$id] = array(
267
    'inputId' => $id,
268
    'source' => url($element['#autocomplete_path'], array('absolute' => TRUE)),
269
  );
270
  drupal_add_js($js_vars, 'setting');
271

    
272
  $output = '<div class="rules-autocomplete">';
273
  $output .= '<input' . drupal_attributes($element['#attributes']) . ' />';
274
  $output .= '</div>';
275

    
276
  return $output;
277
}
278

    
279
/**
280
 * General theme function for displaying settings related help.
281
 * @ingroup themeable
282
 */
283
function theme_rules_settings_help($variables) {
284
  $text = $variables['text'];
285
  $heading = $variables['heading'];
286
  return "<p class=\"rules-settings-help\"><strong>$heading:</strong> $text</p>";
287
}