Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Format Drupal Calendar Module Mini Calendar Title View/Block

Parent Feed: 

Theming the Date and Calendar modules can sometimes be a little tricky. I wanted to change the title display for a "mini" calendar in a block from "Month" to "Month YYYY" (e.g., "October 2010"). In order to do this you need to first learn how to override a theme function.

Now that you're up to par on theme overrides, we can override this theme function: /modules/date/theme/theme.inc: theme_date_nav_title. You'll have something that looks like this in Drupal 6.x.

In my case, I just had to adjust the ternary IF statement to always display 'F Y' as the date format, but you can adjust whatever you wish here.

<?php
/**
* Theme the calendar title
*/
function [your_template_name]_date_nav_title($granularity, $view, $link = FALSE, $format = NULL) {
  switch (
$granularity) {
    case
'year':
     
$title = $view->date_info->year;
     
$date_arg = $view->date_info->year;
      break;
    case
'month':
     
$format = !empty($format) ? $format : (empty($view->date_info->mini) ? 'F Y' : 'F Y');
     
$title = date_format_date($view->date_info->min_date, 'custom', $format);
     
$date_arg = $view->date_info->year .'-'. date_pad($view->date_info->month);
      break;
    case
'day':
     
$format = !empty($format) ? $format : (empty($view->date_info->mini) ? 'l, F j Y' : 'l, F j');
     
$title = date_format_date($view->date_info->min_date, 'custom', $format);
     
$date_arg = $view->date_info->year .'-'. date_pad($view->date_info->month) .'-'. date_pad($view->date_info->day);
      break;
    case
'week':
     
$format = !empty($format) ? $format : (empty($view->date_info->mini) ? 'F j Y' : 'F j');
     
$title = t('Week of @date', array('@date' => date_format_date($view->date_info->min_date, 'custom', $format)));
     
$date_arg = $view->date_info->year .'-W'. date_pad($view->date_info->week);
      break;
  }
  if (!empty(
$view->date_info->mini) || $link) {
   
// Month navigation titles are used as links in the mini view.
   
$attributes = array('title' => t('View full page month'));
   
$url = date_real_url($view, $granularity, $date_arg, TRUE);
    return
l($title, $url, array('attributes' => $attributes));
  }
  else {
    return
$title;
  }
}
?>

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web