template.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * Add body classes if certain regions have content.
  4. */
  5. function bartik_preprocess_html(&$variables) {
  6. if (!empty($variables['page']['featured'])) {
  7. $variables['classes_array'][] = 'featured';
  8. }
  9. if (!empty($variables['page']['triptych_first'])
  10. || !empty($variables['page']['triptych_middle'])
  11. || !empty($variables['page']['triptych_last'])) {
  12. $variables['classes_array'][] = 'triptych';
  13. }
  14. if (!empty($variables['page']['footer_firstcolumn'])
  15. || !empty($variables['page']['footer_secondcolumn'])
  16. || !empty($variables['page']['footer_thirdcolumn'])
  17. || !empty($variables['page']['footer_fourthcolumn'])) {
  18. $variables['classes_array'][] = 'footer-columns';
  19. }
  20. // Add conditional stylesheets for IE
  21. drupal_add_css(path_to_theme() . '/css/ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 7', '!IE' => FALSE), 'preprocess' => FALSE));
  22. drupal_add_css(path_to_theme() . '/css/ie6.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'IE 6', '!IE' => FALSE), 'preprocess' => FALSE));
  23. }
  24. /**
  25. * Override or insert variables into the page template for HTML output.
  26. */
  27. function bartik_process_html(&$variables) {
  28. // Hook into color.module.
  29. if (module_exists('color')) {
  30. _color_html_alter($variables);
  31. }
  32. }
  33. /**
  34. * Override or insert variables into the page template.
  35. */
  36. function bartik_process_page(&$variables) {
  37. // Hook into color.module.
  38. if (module_exists('color')) {
  39. _color_page_alter($variables);
  40. }
  41. // Always print the site name and slogan, but if they are toggled off, we'll
  42. // just hide them visually.
  43. $variables['hide_site_name'] = theme_get_setting('toggle_name') ? FALSE : TRUE;
  44. $variables['hide_site_slogan'] = theme_get_setting('toggle_slogan') ? FALSE : TRUE;
  45. if ($variables['hide_site_name']) {
  46. // If toggle_name is FALSE, the site_name will be empty, so we rebuild it.
  47. $variables['site_name'] = filter_xss_admin(variable_get('site_name', 'Drupal'));
  48. }
  49. if ($variables['hide_site_slogan']) {
  50. // If toggle_site_slogan is FALSE, the site_slogan will be empty, so we rebuild it.
  51. $variables['site_slogan'] = filter_xss_admin(variable_get('site_slogan', ''));
  52. }
  53. // Since the title and the shortcut link are both block level elements,
  54. // positioning them next to each other is much simpler with a wrapper div.
  55. if (!empty($variables['title_suffix']['add_or_remove_shortcut']) && $variables['title']) {
  56. // Add a wrapper div using the title_prefix and title_suffix render elements.
  57. $variables['title_prefix']['shortcut_wrapper'] = array(
  58. '#markup' => '<div class="shortcut-wrapper clearfix">',
  59. '#weight' => 100,
  60. );
  61. $variables['title_suffix']['shortcut_wrapper'] = array(
  62. '#markup' => '</div>',
  63. '#weight' => -99,
  64. );
  65. // Make sure the shortcut link is the first item in title_suffix.
  66. $variables['title_suffix']['add_or_remove_shortcut']['#weight'] = -100;
  67. }
  68. }
  69. /**
  70. * Implements hook_preprocess_maintenance_page().
  71. */
  72. function bartik_preprocess_maintenance_page(&$variables) {
  73. // By default, site_name is set to Drupal if no db connection is available
  74. // or during site installation. Setting site_name to an empty string makes
  75. // the site and update pages look cleaner.
  76. // @see template_preprocess_maintenance_page
  77. if (!$variables['db_is_active']) {
  78. $variables['site_name'] = '';
  79. }
  80. drupal_add_css(drupal_get_path('theme', 'bartik') . '/css/maintenance-page.css');
  81. }
  82. /**
  83. * Override or insert variables into the maintenance page template.
  84. */
  85. function bartik_process_maintenance_page(&$variables) {
  86. // Always print the site name and slogan, but if they are toggled off, we'll
  87. // just hide them visually.
  88. $variables['hide_site_name'] = theme_get_setting('toggle_name') ? FALSE : TRUE;
  89. $variables['hide_site_slogan'] = theme_get_setting('toggle_slogan') ? FALSE : TRUE;
  90. if ($variables['hide_site_name']) {
  91. // If toggle_name is FALSE, the site_name will be empty, so we rebuild it.
  92. $variables['site_name'] = filter_xss_admin(variable_get('site_name', 'Drupal'));
  93. }
  94. if ($variables['hide_site_slogan']) {
  95. // If toggle_site_slogan is FALSE, the site_slogan will be empty, so we rebuild it.
  96. $variables['site_slogan'] = filter_xss_admin(variable_get('site_slogan', ''));
  97. }
  98. }
  99. /**
  100. * Override or insert variables into the node template.
  101. */
  102. function bartik_preprocess_node(&$variables) {
  103. if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) {
  104. $variables['classes_array'][] = 'node-full';
  105. }
  106. }
  107. /**
  108. * Override or insert variables into the block template.
  109. */
  110. function bartik_preprocess_block(&$variables) {
  111. // In the header region visually hide block titles.
  112. if ($variables['block']->region == 'header') {
  113. $variables['title_attributes_array']['class'][] = 'element-invisible';
  114. }
  115. }
  116. /**
  117. * Implements theme_menu_tree().
  118. */
  119. function bartik_menu_tree($variables) {
  120. return '<ul class="menu clearfix">' . $variables['tree'] . '</ul>';
  121. }
  122. /**
  123. * Implements theme_field__field_type().
  124. */
  125. function bartik_field__taxonomy_term_reference($variables) {
  126. $output = '';
  127. // Render the label, if it's not hidden.
  128. if (!$variables['label_hidden']) {
  129. $output .= '<h3 class="field-label">' . $variables['label'] . ': </h3>';
  130. }
  131. // Render the items.
  132. $output .= ($variables['element']['#label_display'] == 'inline') ? '<ul class="links inline">' : '<ul class="links">';
  133. foreach ($variables['items'] as $delta => $item) {
  134. $output .= '<li class="taxonomy-term-reference-' . $delta . '"' . $variables['item_attributes'][$delta] . '>' . drupal_render($item) . '</li>';
  135. }
  136. $output .= '</ul>';
  137. // Render the top-level DIV.
  138. $output = '<div class="' . $variables['classes'] . (!in_array('clearfix', $variables['classes_array']) ? ' clearfix' : '') . '"' . $variables['attributes'] .'>' . $output . '</div>';
  139. return $output;
  140. }