Drupal (6) Calendar: Mark first and last day of a date series (start and end date)

Drupal (6) Calendar: Mark first and last day of a date series (start and end date)

Sometimes it is required to mark the start and end date of a date series (node with from-till date // start - end) graphically.

All we need to to that is a "calendar-date-start" and "calendar-date-end" class for these days, but Drupal 6 Calendar does not provide that!

So I had to find a way and i found! Just use this template preprocess function:

  1. /**
  2.  * Create the calendar date box.
  3.  */
  4. function YOUR_THEME_preprocess_calendar_datebox(&$vars) {
  5.   template_preprocess_calendar_datebox(&$vars);
  6.   $date = $vars['date'];
  7.  
  8.   $date_start = $vars['items'][$date]['00:00:00'][0]->date_start;
  9.   if (!empty($date_start) && $date == $date_start->format('Y-m-d')) {
  10.     $vars['class'] .= ' webks-calendar-date-start';
  11.   }
  12.   $date_end = $vars['items'][$date]['00:00:00'][0]->date_end;
  13.   if (!empty($date_end) && $date == $date_end->format('Y-m-d')) {
  14.     $vars['class'] .= ' webks-calendar-date-end';
  15.   }
  16.   else {
  17.     if (!empty($date_start)) {
  18.       $preDay = $date_start->sub(new DateInterval('P1D'));
  19.       if (!empty($preDay)) {
  20.         $date_end = $vars['items'][$preDay->format('Y-m-d')]['00:00:00'][0]->date_end;
  21.         if (!empty($date_end) && $date == $date_end->format('Y-m-d')) {
  22.           $vars['class'] .= ' webks-calendar-date-end';
  23.         }
  24.       }
  25.     }
  26.   }
  27. }

Important: This only works for "All Day"-Dates, but can easily be modified for other cases, I think.

You can see the results above. Don't forget to add some color lines to your css files, for example:

  1. .calendar-date-start {
  2.   background-color: #FFFCBA !important;
  3. }
  4.  
  5. .calendar-date-end {
  6.   background-color: #E1CAFF !important;
  7. }

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.

Weitere Informationen über Formatierungsoptionen