protected function Calendar::buildCalendarDataStructure in Content Planner 8
Build data structure for Calendar.
Return value
array The data for the calendar.
Throws
\Exception
1 call to Calendar::buildCalendarDataStructure()
- Calendar::build in modules/
content_calendar/ src/ Component/ Calendar.php - Creates the render array for the calendar.
File
- modules/
content_calendar/ src/ Component/ Calendar.php, line 160
Class
Namespace
Drupal\content_calendar\ComponentCode
protected function buildCalendarDataStructure() {
$today_datetime = new \DateTime();
$today_datetime
->setTime(0, 0, 0);
$one_day_interval = new \DateInterval('P1D');
// Get the first date of a given month.
$datetime = DateTimeHelper::getFirstDayOfMonth($this->month, $this->year);
$scaffold_data = [
'calendar_id' => $this
->generateCalendarId(),
'month' => $this->month,
'year' => $this->year,
'label' => DateTimeHelper::getMonthLabelByNumber($this->month) . ' ' . $this->year,
'first_date_weekday' => $datetime
->format('N'),
'days' => [],
];
// Calculate the days in a month.
$days_in_month = DateTimeHelper::getDayCountInMonth($this->month, $this->year);
// Build all dates in a month.
$i = 1;
while ($i <= $days_in_month) {
$scaffold_data['days'][] = [
'date' => $datetime
->format('Y-m-d'),
'day' => $datetime
->format('j'),
'weekday' => $datetime
->format('N'),
'nodes' => [],
'is_today' => $today_datetime == $datetime ? TRUE : FALSE,
];
$i++;
$datetime
->add($one_day_interval);
}
return $scaffold_data;
}