facetapi.theme.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * @file
  4. * Theme functions for the Facet API module.
  5. */
  6. /**
  7. * Returns HTML for a "missing" facet link.
  8. *
  9. * @param $variables
  10. * An associative array containing:
  11. * - field_name: The name of the facet field.
  12. *
  13. * @ingroup themeable
  14. */
  15. function theme_facetapi_facet_missing($variables) {
  16. return t('Missing %field_name', array('%field_name' => $variables['field_name']));
  17. }
  18. /**
  19. * Returns HTML for the facet title, usually the title of the block.
  20. *
  21. * @param $variables
  22. * An associative array containing:
  23. * - title: The title of the facet.
  24. * - facet: The facet definition as returned by facetapi_facet_load().
  25. *
  26. * @ingroup themeable
  27. */
  28. function theme_facetapi_title($variables) {
  29. return t('Filter by @title:', array('@title' => drupal_strtolower($variables['title'])));
  30. }
  31. /**
  32. * Returns HTML for an inactive facet item.
  33. *
  34. * @param $variables
  35. * An associative array containing the keys 'text', 'path', 'options', and
  36. * 'count'. See the l() and theme_facetapi_count() functions for information
  37. * about these variables.
  38. *
  39. * @ingroup themeable
  40. */
  41. function theme_facetapi_link_inactive($variables) {
  42. // Builds accessible markup.
  43. // @see http://drupal.org/node/1316580
  44. $accessible_vars = array(
  45. 'text' => $variables['text'],
  46. 'active' => FALSE,
  47. );
  48. $accessible_markup = theme('facetapi_accessible_markup', $accessible_vars);
  49. // Sanitizes the link text if necessary.
  50. $sanitize = empty($variables['options']['html']);
  51. $variables['text'] = ($sanitize) ? check_plain($variables['text']) : $variables['text'];
  52. // Adds count to link if one was passed.
  53. if (isset($variables['count'])) {
  54. $variables['text'] .= ' ' . theme('facetapi_count', $variables);
  55. }
  56. // Resets link text, sets to options to HTML since we already sanitized the
  57. // link text and are providing additional markup for accessibility.
  58. $variables['text'] .= $accessible_markup;
  59. $variables['options']['html'] = TRUE;
  60. return theme_link($variables);
  61. }
  62. /**
  63. * Returns HTML for the active facet item's count.
  64. *
  65. * @param $variables
  66. * An associative array containing:
  67. * - count: The item's facet count.
  68. *
  69. * @ingroup themeable
  70. */
  71. function theme_facetapi_count($variables) {
  72. return '(' . (int) $variables['count'] . ')';
  73. }
  74. /**
  75. * Returns HTML for an active facet item.
  76. *
  77. * @param $variables
  78. * An associative array containing the keys 'text', 'path', and 'options'. See
  79. * the l() function for information about these variables.
  80. *
  81. * @see l()
  82. *
  83. * @ingroup themeable
  84. */
  85. function theme_facetapi_link_active($variables) {
  86. // Sanitizes the link text if necessary.
  87. $sanitize = empty($variables['options']['html']);
  88. $link_text = ($sanitize) ? check_plain($variables['text']) : $variables['text'];
  89. // Theme function variables fro accessible markup.
  90. // @see http://drupal.org/node/1316580
  91. $accessible_vars = array(
  92. 'text' => $variables['text'],
  93. 'active' => TRUE,
  94. );
  95. // Builds link, passes through t() which gives us the ability to change the
  96. // position of the widget on a per-language basis.
  97. $replacements = array(
  98. '!facetapi_deactivate_widget' => theme('facetapi_deactivate_widget', $variables),
  99. '!facetapi_accessible_markup' => theme('facetapi_accessible_markup', $accessible_vars),
  100. );
  101. $variables['text'] = t('!facetapi_deactivate_widget !facetapi_accessible_markup', $replacements);
  102. $variables['options']['html'] = TRUE;
  103. return theme_link($variables) . $link_text;
  104. }
  105. /**
  106. * Returns HTML for the deactivation widget.
  107. *
  108. * @param $variables
  109. * An associative array containing the keys 'text', 'path', and 'options'. See
  110. * the l() function for information about these variables.
  111. *
  112. * @see l()
  113. * @see theme_facetapi_link_active()
  114. *
  115. * @ingroup themable
  116. */
  117. function theme_facetapi_deactivate_widget($variables) {
  118. return '(-)';
  119. }
  120. /**
  121. * Returns HTML that adds accessible markup to facet links.
  122. *
  123. * @param $variables
  124. * An associative array containing:
  125. * - text: The text of the facet link.
  126. * - active: Whether the item is active or not.
  127. *
  128. * @ingroup themeable
  129. *
  130. * @see http://drupal.org/node/1316580
  131. */
  132. function theme_facetapi_accessible_markup($variables) {
  133. $vars = array('@text' => $variables['text']);
  134. $text = ($variables['active']) ? t('Remove @text filter', $vars) : t('Apply @text filter', $vars);
  135. // Add spaces before and after the text, since other content may be displayed
  136. // inline with this and we don't want the words to run together. However, the
  137. // spaces must be inside the <span> so as not to disrupt the layout for
  138. // sighted users.
  139. return '<span class="element-invisible"> ' . $text . ' </span>';
  140. }