Improve date handling for the calendar widget

This commit is contained in:
2026-04-06 08:49:14 +02:00
parent 5c74c2e667
commit c1ffbc3f3a
2 changed files with 71 additions and 21 deletions

View File

@@ -91,6 +91,16 @@ class syntax_plugin_luxtools_calendar extends SyntaxPlugin
$size = ChronologicalCalendarWidget::normalizeSize((string)($data['size'] ?? 'large'));
$showTimes = (bool)($data['show_times'] ?? true);
if ($size === 'small') {
$resolved = $this->resolveMonthFromCookie(
'luxtools_calendar_month_' . preg_replace('/[^a-zA-Z0-9]/', '_', $baseNs)
) ?? $this->resolveMonthFromCookie('luxtools_client_month');
if ($resolved !== null) {
$year = $resolved['year'];
$month = $resolved['month'];
}
}
$slots = CalendarSlot::loadEnabled($this);
$widgetSlots = CalendarSlot::filterWidgetVisible($slots);
$indicators = [];
@@ -122,6 +132,25 @@ class syntax_plugin_luxtools_calendar extends SyntaxPlugin
return true;
}
/**
* @param string $cookieName
* @return array{year:int,month:int}|null
*/
protected function resolveMonthFromCookie(string $cookieName): ?array
{
$raw = $_COOKIE[$cookieName] ?? null;
if ($raw === null) return null;
$decoded = json_decode($raw, true);
if (!is_array($decoded)) return null;
$year = (int)($decoded['year'] ?? 0);
$month = (int)($decoded['month'] ?? 0);
if ($year < 1 || $month < 1 || $month > 12) return null;
return ['year' => $year, 'month' => $month];
}
/**
* @param string $flags
* @return array<string,string>