Skip to content

Commit

Permalink
Check if years array is empty before accessing index
Browse files Browse the repository at this point in the history
  • Loading branch information
amym-li committed Jun 2, 2023
1 parent 8b1e590 commit 6d238b2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Plugin/views/style/FullCalendarSolr.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,14 @@ public function render() {
sort($years);

// Get the calendar's initial year.
// Check if a year is provided in the path.
if (isset($path[$year_index + 1]) && is_numeric($path[$year_index + 1])) {
$this->options['fullcalendar_options']['initialDate'] = $path[$year_index + 1];
}
else {
$this->options['fullcalendar_options']['initialDate'] = $years[0] ?: (new \DateTime())->format('Y-m-d');
// If no year provided in the path, use the earliest year with results.
// If no years have results, use the current year.
$this->options['fullcalendar_options']['initialDate'] = !empty($years) ? $years[0] : (new \DateTime())->format('Y-m-d');
}

return [
Expand Down

0 comments on commit 6d238b2

Please sign in to comment.