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