Steps towards handling end dates in Calendar 8
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #2699477. -->
Reported by: [13jupiters](https://www.drupal.org/user/2724141)
Related to !8
>>>
<p>By working closely against D7 Calendar, I've updated Calendar 8-dev so that calendars display multi-day events as expected.</p>
<p>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).</p>
<p>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.</p>
<p>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:</p>
<pre> foreach ($this->view->result as $row_index => $row) {<br> $this->view->row_index = $row_index;<br> $events = $this->view->rowPlugin->render($row);<br> // @todo Check what comes out here.<br> /** @var \Drupal\calendar\CalendarEvent $event_info */<br> foreach ($events as $event_info) {<br> $item_start = $event_info->calendar_start_date->format('Y-m-d');<br> //$item_start = $event_info->getStartDate()->format('Y-m-d');<br> $item_end = $event_info->calendar_end_date->format('Y-m-d');<br> //$item_end = $event_info->getEndDate()->format('Y-m-d');<br> $time_start = $event_info->calendar_start_date->format('H:i:s');<br> //$time_start = $event_info->getStartDate()->format('H:i:s');<br> $event_info->setRenderedFields($this->rendered_fields[$row_index]);<br> $items[$item_start][$time_start][] = $event_info;<br> }</pre><p>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). </p>
<p>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.</p>
<p>A couple of other overall notes:<br>
- working on this requires <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/drupal/issues/2161337" title="Status: Closed (fixed)">#2161337: Add a Date Range field type with support for end date</a></span> patch #90<br>
- I haven't addressed any of the pre-existing to-do's in Calendar dev - hardcoding of granularities and so on<br>
- recommend grabbing Calendar 7.x-3.5 for full comparison if you're trying to grasp 8</p>
> Related issue: [Issue #2604550](https://www.drupal.org/node/2604550)
> Related issue: [Issue #2786577](https://www.drupal.org/node/2786577)
issue