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>&nbsp;&nbsp;&nbsp; foreach ($this-&gt;view-&gt;result as $row_index =&gt; $row) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;view-&gt;row_index = $row_index;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $events = $this-&gt;view-&gt;rowPlugin-&gt;render($row);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // @todo Check what comes out here.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /** @var \Drupal\calendar\CalendarEvent $event_info */<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach ($events as $event_info) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $item_start = $event_info-&gt;calendar_start_date-&gt;format('Y-m-d');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //$item_start = $event_info-&gt;getStartDate()-&gt;format('Y-m-d');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $item_end = $event_info-&gt;calendar_end_date-&gt;format('Y-m-d');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //$item_end = $event_info-&gt;getEndDate()-&gt;format('Y-m-d');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $time_start = $event_info-&gt;calendar_start_date-&gt;format('H:i:s');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //$time_start = $event_info-&gt;getStartDate()-&gt;format('H:i:s');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $event_info-&gt;setRenderedFields($this-&gt;rendered_fields[$row_index]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $items[$item_start][$time_start][] = $event_info;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</pre><p>The entity being placed on the calendar has event_info-&gt;start_date and event_info-&gt;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-&gt;getStartDate() etc. However, Calendar requires that the entity also have a "calendar_start_date" and a "calendar_end_date". Later, in calendarBuildWeekDay(), the entity-&gt;start_date is compared to entity-&gt;calendar_start_date to determine whether we have an event spanning multiple days or not (ditto the end_date &amp; 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