current_search.theme.inc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * @file
  4. * Theme functions for the Current Search Blocks module.
  5. */
  6. /**
  7. * Returns HTML for the inactive facet item's count.
  8. *
  9. * @param $variables
  10. * An associative array containing:
  11. * - text: The text being displayed.
  12. * - wrapper: A boolean flagging whether wrapper markup should be added.
  13. * - element: The HTML element the text is wrapped in.
  14. * - css: A boolean flagging whether a CSS class should be added to the
  15. * wrapper element.
  16. * - class: An array of CSS classes.
  17. * - options: An associative array of options containing:
  18. * - html: Whether or not "text" is rendered HTML, otherwise the string is
  19. * passed through check_plain(). Defaults to FALSE.
  20. *
  21. * @ingroup themeable
  22. */
  23. function theme_current_search_text(array $variables) {
  24. // Initializes output, sanitizes text if necessary.
  25. $sanitize = empty($variables['options']['html']);
  26. $output = ($sanitize) ? check_plain($variables['text']) : $variables['text'];
  27. // Adds wrapper markup and CSS classes.
  28. if ($variables['wrapper'] && $variables['element']) {
  29. $attributes = array('class' => $variables['class']);
  30. $element = check_plain($variables['element']);
  31. $output = '<' . $element . drupal_attributes($attributes) . '>' . $output . '</' . $element . '>';
  32. }
  33. return $output;
  34. }
  35. /**
  36. * Returns HTML for the group list title.
  37. *
  38. * @param $variables
  39. * An associative array containing:
  40. * - title: The title of the group list.
  41. *
  42. * @ingroup themeable
  43. */
  44. function theme_current_search_group_title(array $variables) {
  45. return '<h4 class="current-search-group-title">' . $variables['title'] . '</h4>';
  46. }
  47. /**
  48. * Adds wrapper markup around the current search item.
  49. *
  50. * @param $variables
  51. * An associative array containing:
  52. * - element: The render array for the current search item.
  53. *
  54. * @ingroup themeable
  55. */
  56. function theme_current_search_item_wrapper(array $variables) {
  57. $element = $variables['element'];
  58. $attributes = array(
  59. 'class' => array(
  60. 'current-search-item',
  61. drupal_html_class('current-search-item-' . $element['#current_search_id']),
  62. drupal_html_class('current-search-item-' . $element['#current_search_name']),
  63. ),
  64. );
  65. return '<div' . drupal_attributes($attributes) . '>' . $element['#children'] . '</div>';
  66. }
  67. /**
  68. * Adds wrapper markup around the group.
  69. *
  70. * @param $variables
  71. * An associative array containing:
  72. * - element: The render array for the current search group.
  73. *
  74. * @ingroup themeable
  75. */
  76. function theme_current_search_group_wrapper(array $variables) {
  77. $element = $variables['element'];
  78. $attributes = array('class' => array('current-search-group current-search-group-' . drupal_html_class($element['#facet_name'])), 'id' => $element['#id']);
  79. return '<div' . drupal_attributes($attributes) . '>' . $element['#children'] . '</div>';
  80. }
  81. /**
  82. * Returns HTML for a grouped active facet item.
  83. *
  84. * @param $variables
  85. * An associative array containing the keys 'text', 'path', 'options', and
  86. * 'count'.
  87. *
  88. * @ingroup themeable
  89. */
  90. function theme_current_search_link_active($variables) {
  91. // Builds accessible markup.
  92. // @see http://drupal.org/node/1316580
  93. $accessible_vars = array(
  94. 'text' => $variables['text'],
  95. 'active' => TRUE,
  96. );
  97. $accessible_markup = theme('facetapi_accessible_markup', $accessible_vars);
  98. // Sanitizes the link text if necessary.
  99. $sanitize = empty($variables['options']['html']);
  100. $variables['text'] = ($sanitize) ? check_plain($variables['text']) : $variables['text'];
  101. // Adds the deactivation widget.
  102. $variables['text'] .= theme('current_search_deactivate_widget');
  103. // Resets link text, sets to options to HTML since we already sanitized the
  104. // link text and are providing additional markup for accessibility.
  105. $variables['text'] .= ' ' . $accessible_markup;
  106. $variables['options']['html'] = TRUE;
  107. return theme_link($variables);
  108. }
  109. /**
  110. * Returns HTML for a search keys facet item.
  111. *
  112. * @param $variables
  113. * An associative array containing the keys 'keys' and 'adapter'.
  114. *
  115. * @ingroup themeable
  116. */
  117. function theme_current_search_keys($variables) {
  118. return check_plain($variables['keys']);
  119. }
  120. /**
  121. * Returns HTML for the deactivation widget.
  122. *
  123. * @param $variables
  124. * An associative array containing the keys 'text', 'path', 'options', and
  125. * 'count'.
  126. *
  127. * @ingroup themeable
  128. */
  129. function theme_current_search_deactivate_widget($variables) {
  130. return ' [X]';
  131. }
  132. /**
  133. * Returns the sort table.
  134. *
  135. * @param $variables
  136. * An associative array containing:
  137. * - element: A render element representing the form.
  138. *
  139. * @ingroup themeable
  140. */
  141. function theme_current_search_sort_settings_table($variables) {
  142. $output = '';
  143. // Builds table rows.
  144. $rows = array();
  145. foreach ($variables['element']['#current_search']['items'] as $name => $settings) {
  146. $rows[$name] = array(
  147. 'class' => array('draggable'),
  148. 'data' => array(
  149. drupal_render($variables['element'][$name]['item']),
  150. drupal_render($variables['element'][$name]['weight']),
  151. array(
  152. 'data' => drupal_render($variables['element'][$name]['remove']),
  153. 'class' => 'current-search-remove-link',
  154. ),
  155. ),
  156. );
  157. }
  158. // Builds table with drabble rows, returns output.
  159. $table_id = 'current-search-sort-settings';
  160. drupal_add_tabledrag($table_id, 'order', 'sibling', 'current-search-sort-weight');
  161. $output .= drupal_render_children($variables['element']);
  162. $output .= theme('table', array('rows' => $rows, 'attributes' => array('id' => $table_id)));
  163. return $output;
  164. }