Friday 26 June 2015

Template customization

<?php

/**
 * Add body classes if certain regions have content.
 */
function bartik_preprocess_html(&$variables) {
  if (!empty($variables['page']['featured'])) {
    $variables['classes_array'][] = 'featured';
  }

  if (!empty($variables['page']['triptych_first'])
    || !empty($variables['page']['triptych_middle'])
    || !empty($variables['page']['triptych_last'])) {
    $variables['classes_array'][] = 'triptych';
  }

  if (!empty($variables['page']['footer_firstcolumn'])
    || !empty($variables['page']['footer_secondcolumn'])
    || !empty($variables['page']['footer_thirdcolumn'])
    || !empty($variables['page']['footer_fourthcolumn'])) {
    $variables['classes_array'][] = 'footer-columns';
  }

  // Add conditional stylesheets for IE
  drupal_add_css(path_to_theme() . '/css/ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 7', '!IE' => FALSE), 'preprocess' => FALSE));
  drupal_add_css(path_to_theme() . '/css/ie6.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'IE 6', '!IE' => FALSE), 'preprocess' => FALSE));
}

/**
 * Override or insert variables into the page template for HTML output.
 */
function sdfcu_process_html(&$variables) {
  // Hook into color.module.
  if (module_exists('color')) {
    _color_html_alter($variables);
  }
}

/**
 * Override or insert variables into the page template.
 */
function sdfcu_process_page(&$variables) {
  // Hook into color.module.
  if (module_exists('color')) {
    _color_page_alter($variables);
  }
  // Always print the site name and slogan, but if they are toggled off, we'll
  // just hide them visually.
  $variables['hide_site_name']   = theme_get_setting('toggle_name') ? FALSE : TRUE;
  $variables['hide_site_slogan'] = theme_get_setting('toggle_slogan') ? FALSE : TRUE;
  if ($variables['hide_site_name']) {
    // If toggle_name is FALSE, the site_name will be empty, so we rebuild it.
    $variables['site_name'] = filter_xss_admin(variable_get('site_name', 'Drupal'));
  }
  if ($variables['hide_site_slogan']) {
    // If toggle_site_slogan is FALSE, the site_slogan will be empty, so we rebuild it.
    $variables['site_slogan'] = filter_xss_admin(variable_get('site_slogan', ''));
  }
  // Since the title and the shortcut link are both block level elements,
  // positioning them next to each other is much simpler with a wrapper div.
  if (!empty($variables['title_suffix']['add_or_remove_shortcut']) && $variables['title']) {
    // Add a wrapper div using the title_prefix and title_suffix render elements.
    $variables['title_prefix']['shortcut_wrapper'] = array(
      '#markup' => '<div class="shortcut-wrapper clearfix">',
      '#weight' => 100,
    );
    $variables['title_suffix']['shortcut_wrapper'] = array(
      '#markup' => '</div>',
      '#weight' => -99,
    );
    // Make sure the shortcut link is the first item in title_suffix.
    $variables['title_suffix']['add_or_remove_shortcut']['#weight'] = -100;
  }
}

/**
 * Implements hook_preprocess_maintenance_page().
 */
function sdfcu_preprocess_maintenance_page(&$variables) {
  // By default, site_name is set to Drupal if no db connection is available
  // or during site installation. Setting site_name to an empty string makes
  // the site and update pages look cleaner.
  // @see template_preprocess_maintenance_page
  if (!$variables['db_is_active']) {
    $variables['site_name'] = '';
  }
  drupal_add_css(drupal_get_path('theme', 'sdfcu') . '/css/maintenance-page.css');
}

/**
 * Override or insert variables into the maintenance page template.
 */
function sdfcu_process_maintenance_page(&$variables) {
  // Always print the site name and slogan, but if they are toggled off, we'll
  // just hide them visually.
  $variables['hide_site_name']   = theme_get_setting('toggle_name') ? FALSE : TRUE;
  $variables['hide_site_slogan'] = theme_get_setting('toggle_slogan') ? FALSE : TRUE;
  if ($variables['hide_site_name']) {
    // If toggle_name is FALSE, the site_name will be empty, so we rebuild it.
    $variables['site_name'] = filter_xss_admin(variable_get('site_name', 'Drupal'));
  }
  if ($variables['hide_site_slogan']) {
    // If toggle_site_slogan is FALSE, the site_slogan will be empty, so we rebuild it.
    $variables['site_slogan'] = filter_xss_admin(variable_get('site_slogan', ''));
  }
}

/**
 * Override or insert variables into the node template.
 */
function sdfcu_preprocess_node(&$variables) {
  if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) {
    $variables['classes_array'][] = 'node-full';
foreach (array('rates') as $region) {
      $variables[$region] = theme('blocks', $region);
    }
      return $variables;
  }
}

/**
 * Override or insert variables into the block template.
 */
function sdfcu_preprocess_block(&$variables) {
  // In the header region visually hide block titles.
  if ($variables['block']->region == 'header') {
    $variables['title_attributes_array']['class'][] = 'element-invisible';
  }
}

/**
 * Implements theme_menu_tree().
 */
function sdfcu_menu_tree($variables) {
  return '<ul>' . $variables['tree'] . '</ul>';
}


function sdfcu_menu_tree__menu_footer_top_menu(&$variables) {

  return '<ul>' . $variables['tree'] . '</ul>';
}


function sdfcu_menu_link__menu_sdfcu_menu($variables)
{
  $element = $variables['element'];
  $sub_menu = '';

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
 
  // This example is adds the depth class just for a specific menu. Change 'menu-name' to your menu name.
  if ($element['#original_link']['menu_name'] == 'menu-sdfcu-menu') {
if($element['#original_link']['depth'] == 2)
  {
  $class1 = strtolower(str_replace(' ','-',$element['#original_link']['link_title']));
  $class = str_replace('?','',$class1). " menu-level-2";
  return '<li class="'.$class.'">' . $output . $sub_menu . "</li>\n";
  }
if($element['#original_link']['depth'] == 1)
  {
  $class1 = strtolower(str_replace(' ','-',$element['#original_link']['link_title']));
  $class = $class1. " dropdown";
 
  return '<li class="'.$class.'">' . $output .'<b class="caret"></b>'. $sub_menu . '</li>';
 
  }
  if($element['#original_link']['depth'] == 2)
  {
  $class1 = strtolower(str_replace(' ','-',$element['#original_link']['link_title']));
  $class = str_replace('?','',$class1). " menu-level-2";
  return '<li class="'.$class.'">' . $output . $sub_menu . "</li>\n";
  }
if($element['#original_link']['depth'] == 3)
  {
  $class1 = strtolower(str_replace(' ','-',$element['#original_link']['link_title']));
  $class = str_replace('?','',$class1). " menu-level-3";
  return '<li class="'.$class.'">' . $output . $sub_menu . "</li>\n";
  }
if($element['#original_link']['depth'] == 4)
  {
  $class1 = strtolower(str_replace(' ','-',$element['#original_link']['link_title']));
  $class = str_replace('?','',$class1). " menu-level-4";
  return '<li class="'.$class.'">' . $output . $sub_menu . "</li>\n";
  }  
  else {
    return '<li>' . $output . $sub_menu . "</li>\n";
  }

}
  }
 




function sdfcu_menu_link__menu_footer_top_menu($variables)
{
  $element = $variables['element'];
  $sub_menu = '';

  $element['#attributes']['class'][] = 'menu-' . $element['#original_link']['mlid'];

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li class="col-lg-4 col-md-4 col-sm-12 col-xs-12">' . $output . $sub_menu . '</li>';
}

function sdfcu_menu_link__menu_footer_menu($variables)
{
$element = $variables['element'];
  $sub_menu = '';
 
if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
    $element = $variables['element'];
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
if($element['#original_link']['depth'] == 1)
{
return '<li class="col-lg-4 col-md-4 col-sm-12 col-xs-12">' . $output . $sub_menu . '</li>';
}

else
{
return '<li>' . $output . $sub_menu . '</li>';
}
}

/**
 * Implements theme_field__field_type().
 */
function sdfcu_field__taxonomy_term_reference($variables) {
  $output = '';

  // Render the label, if it's not hidden.
  if (!$variables['label_hidden']) {
    $output .= '<h3 class="field-label">' . $variables['label'] . ': </h3>';
  }

  // Render the items.
  $output .= ($variables['element']['#label_display'] == 'inline') ? '<ul class="links inline">' : '<ul class="links">';
  foreach ($variables['items'] as $delta => $item) {
    $output .= '<li class="taxonomy-term-reference-' . $delta . '"' . $variables['item_attributes'][$delta] . '>' . drupal_render($item) . '</li>';
  }
  $output .= '</ul>';

  // Render the top-level DIV.
  $output = '<div class="' . $variables['classes'] . (!in_array('clearfix', $variables['classes_array']) ? ' clearfix' : '') . '"' . $variables['attributes'] .'>' . $output . '</div>';

  return $output;
}


function sdfcu_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'search_block_form') {
 
    $form['search_block_form']['#title'] = t('Search'); // Change the text on the label element
    $form['search_block_form']['#title_display'] = 'invisible'; // Toggle label visibilty
    $form['search_block_form']['#size'] = 40;  // define size of the textfield
    $form['search_block_form']['#default_value'] = t('Search'); // Set a default value for the textfield
    $form['actions']['submit']['#value'] = t('GO!'); // Change the text on the submit button
    $form['actions']['submit'] = array('#type' => 'image_button', '#src' => base_path() . path_to_theme() . '/images/search-ico.png');

$form['search_block_form']['#prefix']= '<li class="search">';
$form['search_block_form']['#suffix']= "</li>";
    // Add extra attributes to the text box
    $form['search_block_form']['#attributes']['onblur'] = "if (this.value == '') {this.value = 'Search';}";
    $form['search_block_form']['#attributes']['onfocus'] = "if (this.value == 'Search') {this.value = '';}";
    // Prevent user from searching the default text
    $form['#attributes']['onsubmit'] = "if(this.search_block_form.value=='Search'){ alert('Please enter a search'); return false; }";

    // Alternative (HTML5) placeholder attribute instead of using the javascript
    $form['search_block_form']['#attributes']['placeholder'] = t('Search');
  }
 
 
}




  // Helper function used below.
  function _menu_subtree_data($item, $tree) {
    foreach ($tree as $cid => $data) {
      if ($item['mlid'] == $data['link']['mlid']) {
        return array($cid => $data);
      }

      if ($data['below']) {
        $return = _menu_subtree_data($item, $data['below']);
        if ($return) {
          return $return;
        }
      }
    }
    return FALSE;
  }

No comments:

Post a Comment