Steps towards handling end dates in Calendar 8

Created on 4 April 2016, over 8 years ago
Updated 24 October 2023, about 1 year ago

By working closely against D7 Calendar, I've updated Calendar 8-dev so that calendars display multi-day events as expected.

However - my solution so far is not nearly ready to commit, so I'm starting this thread (after discussion w/ pjonckiere) simply to spark discussion/work. I'm fairly confident I've isolated the areas which need changing, less confident that my changes are correct (even if they work).

And one major caveat - my working calendar relies on brute hardcoding of some field values in CalendarHelper::dateViewFields. Haven't quite cracked that problem yet.

As an overview: a key to understanding Calendar is found in /src/Plugins/views/style/Calendar.php in function render(). This is where src/Plugins/views/row/Calendar.php function render() (and prerender) are called on. Note this code, with original 8.x-1.x-dev lines commented out:

    foreach ($this->view->result as $row_index => $row) {
      $this->view->row_index = $row_index;
      $events = $this->view->rowPlugin->render($row);
      // @todo Check what comes out here.
      /** @var \Drupal\calendar\CalendarEvent $event_info */
      foreach ($events as $event_info) {
        $item_start = $event_info->calendar_start_date->format('Y-m-d');
        //$item_start = $event_info->getStartDate()->format('Y-m-d');
        $item_end = $event_info->calendar_end_date->format('Y-m-d');
        //$item_end = $event_info->getEndDate()->format('Y-m-d');
        $time_start = $event_info->calendar_start_date->format('H:i:s');
        //$time_start = $event_info->getStartDate()->format('H:i:s');
        $event_info->setRenderedFields($this->rendered_fields[$row_index]);
        $items[$item_start][$time_start][] = $event_info;
      }

The entity being placed on the calendar has event_info->start_date and event_info->end_date (which of course can be the same as the start date). These are being called in the commented out lines via $event_info->getStartDate() etc. However, Calendar requires that the entity also have a "calendar_start_date" and a "calendar_end_date". Later, in calendarBuildWeekDay(), the entity->start_date is compared to entity->calendar_start_date to determine whether we have an event spanning multiple days or not (ditto the end_date & calendar_end_date).

Once you've gleaned that, travel over to /src/Plugins/views/row/Calendar.php, where the heavy lifting happens in the prerender(), render(), and explode_values() functions.

A couple of other overall notes:
- working on this requires #2161337: Add a Date Range field type with support for end date β†’ patch #90
- I haven't addressed any of the pre-existing to-do's in Calendar dev - hardcoding of granularities and so on
- recommend grabbing Calendar 7.x-3.5 for full comparison if you're trying to grasp 8

🌱 Plan
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada 13jupiters

Live updates comments and jobs are added and updated live.
  • Needs manual testing

    The change/bugfix cannot be fully demonstrated by automated testing, and thus requires manual testing in a variety of environments.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States dianacastillo Miami

    what is the progress on this ? I am having and issue in drupal 9.5 there is no longer the option for the view template 'Calendar event Field date_daterange on Calendar'

  • πŸ‡ΊπŸ‡ΈUnited States dianacastillo Miami

    what is the progress on this ? I am having an issue in drupal 9.5 there is no longer the option for the view template 'Calendar event Field date_daterange on Calendar'

Production build 0.71.5 2024