ui.theme.inc 10 KB

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