From 71ca942cfd094b7131a8b7f4209d70d1fde7e4b8 Mon Sep 17 00:00:00 2001 From: raviks789 <33730024+raviks789@users.noreply.github.com> Date: Fri, 20 Oct 2023 14:38:33 +0200 Subject: [PATCH] Calendar: Make `$url` nullable --- library/Notifications/Widget/Calendar.php | 15 ++++++++------- .../Notifications/Widget/Calendar/MonthGrid.php | 12 +++++++----- .../Notifications/Widget/Calendar/WeekGrid.php | 12 +++++++----- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/library/Notifications/Widget/Calendar.php b/library/Notifications/Widget/Calendar.php index 07fc2c44..4e498023 100644 --- a/library/Notifications/Widget/Calendar.php +++ b/library/Notifications/Widget/Calendar.php @@ -51,7 +51,7 @@ class Calendar extends BaseHtmlElement /** @var Url */ protected $addEntryUrl; - /** @var Url */ + /** @var ?Url */ protected $url; public function setControls(Controls $controls): self @@ -89,13 +89,14 @@ public function setUrl(?Url $url): self return $this; } - public function prepareDayViewUrl(DateTime $date): Url + public function prepareDayViewUrl(DateTime $date): ?Url { - $url = clone $this->url; - return $url->overwriteParams([ - 'mode' => 'day', - 'day' => $date->format('Y-m-d') - ]); + return $this->url + ? (clone $this->url)->overwriteParams([ + 'mode' => 'day', + 'day' => $date->format('Y-m-d') + ]) + : null; } protected function getModeStart(): DateTime diff --git a/library/Notifications/Widget/Calendar/MonthGrid.php b/library/Notifications/Widget/Calendar/MonthGrid.php index d53ee06b..65f9dea1 100644 --- a/library/Notifications/Widget/Calendar/MonthGrid.php +++ b/library/Notifications/Widget/Calendar/MonthGrid.php @@ -38,11 +38,13 @@ protected function assembleGridStep(BaseHtmlElement $content, DateTime $step): v $content->addHtml(Text::create($step->format('j'))); $dayViewUrl = $this->calendar->prepareDayViewUrl($step); - $content->addHtml( - (new ExtraEntryCount(null, $dayViewUrl)) - ->setGrid($this) - ->setGridStep($step) - ); + if ($dayViewUrl !== null) { + $content->addHtml( + (new ExtraEntryCount(null, $dayViewUrl)) + ->setGrid($this) + ->setGridStep($step) + ); + } } protected function getRowStartModifier(): int diff --git a/library/Notifications/Widget/Calendar/WeekGrid.php b/library/Notifications/Widget/Calendar/WeekGrid.php index 7e298fbf..f874173f 100644 --- a/library/Notifications/Widget/Calendar/WeekGrid.php +++ b/library/Notifications/Widget/Calendar/WeekGrid.php @@ -120,11 +120,13 @@ protected function assembleGridStep(BaseHtmlElement $content, DateTime $step): v { if ($step->format('H') === '23') { $dayViewUrl = $this->calendar->prepareDayViewUrl($step); - $content->addHtml( - (new ExtraEntryCount(null, $dayViewUrl)) - ->setGrid($this) - ->setGridStep($step) - ); + if ($dayViewUrl !== null) { + $content->addHtml( + (new ExtraEntryCount(null, $dayViewUrl)) + ->setGrid($this) + ->setGridStep($step) + ); + } } }