Skip to content

Commit

Permalink
Calendar: Make $url nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Oct 23, 2023
1 parent 93bca74 commit 71ca942
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
15 changes: 8 additions & 7 deletions library/Notifications/Widget/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Calendar extends BaseHtmlElement
/** @var Url */
protected $addEntryUrl;

/** @var Url */
/** @var ?Url */
protected $url;

public function setControls(Controls $controls): self
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions library/Notifications/Widget/Calendar/MonthGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions library/Notifications/Widget/Calendar/WeekGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}
}

Expand Down

0 comments on commit 71ca942

Please sign in to comment.