Hi all ;).

I need to override a function in the theme module, that returns an array of days in 3 letter format (Mon, Tue, Wed...).

Basically I want to substitute the 3 letter for only 1 (M, T, W). The function that do the trick in the event module is:

function event_week_days() {
  static $weekdays;

  if (!$weekdays) {
    if (variable_get('date_first_day', 1)) {
      $weekdays = array(array('day' => 'Mon', 't' => t('Mon')), array('day' => 'Tue', 't' => t('Tue')), array('day' => 'Wed', 't' => t('Wed')), array('day' => 'Thu', 't' => t('Th
u')), array('day' => 'Fri', 't' => t('Fri')), array('day' => 'Sat', 't' => t('Sat')), array('day' => 'Sun', 't' => t('Sun')));
    }
    else {
      $weekdays = array(array('day' => 'Sun', 't' => t('Sun')), array('day' => 'Mon', 't' => t('Mon')), array('day' => 'Tue', 't' => t('Tue')), array('day' => 'Wed', 't' => t('We
d')), array('day' => 'Thu', 't' => t('Thu')), array('day' => 'Fri', 't' => t('Fri')), array('day' => 'Sat', 't' => t('Sat')));
    }
  }
  return $weekdays;
}

I´ve tried to override it in my theme template file but obviously it didn´t work. Is there any form to rewrite this function without having to touch the event.module code.

Thanks in advance, Simon.

Comments

aosiname’s picture

I had a similar problem in Drupal 6 which also solves this problem.

The calendar prints dates with events as links to the calendar page but the client only wanted the dates to be bold or highlighted - they did not want to link to the calendar page (prefered a view to link straight to node) http://celiaclyne.osinova.co.uk/cookery-school

So i searched around the event module and found event.module with the function event_calendar_month where all the links are generated in the event.module file.

Not wanting to hack the contributed module and the theme was not titled theme_event_calendar_month I was pretty stuck.

Then i found at the end of the function, it returns:
theme('event_calendar_month', $op, $thead, $tbody, $attributes = array('class' => 'event-block '. strtolower($month_name)), $caption);

So figured there must be a theme_event_calendar_month somewhere

So created one in my template.php file to watch it crash so i could find where this function was hiding.

Found it in a file right in front of my eyes in the event module folder called event.theme.

So I overode THAT function using phptemplate_event_calendar_month in my template.php file

Here is the code i used

/**
 * Format a calendar view
 *
 * @param day
 *   The day to display.
 */
function phptemplate_event_calendar_month($op, $header, $rows, $attributes = array(), $caption = NULL) {
#########################################
##### print_r($header) shows all the days of the week. #### 
#####                  you can change them here               ####
#########################################

  foreach($rows as &$row) {
    foreach($row as &$cell) {
      //$cell['data'] = strip_tags($cell['data']);
      
      // replace a href with b id
      $cell['data'] = str_replace("a href", "b id", $cell['data']);
      
      // replace '/' with '-'
      $cell['data'] = str_replace("/", "-", $cell['data']);
      
      // replace <-a> with </b>
      $cell['data'] = str_replace("<-a>", "</b>", $cell['data']);      
    }
  }

  $output = theme("table", $header, $rows, $attributes, $caption);
  return '<div class="event-calendar"><div class="month-view">'. $output ."</div></div>\n";
}

this changed the cell content 
from: <a href="path/to/calendar/event">integer</a> 
into: <b id="path-to-calendar-event">integer</b>

There are other functions starting with theme_ inside event.theme so those may help with similar problems.