ui.theme.inc 10 KB

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