From 50ee137cb546e463aefca899f76281519676f39a Mon Sep 17 00:00:00 2001 From: agnonym Date: Wed, 29 Nov 2023 11:21:10 +0100 Subject: [PATCH] + | Column - Listing - Link --- src/Services/Listings/Columns/Link.php | 60 ++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/Services/Listings/Columns/Link.php diff --git a/src/Services/Listings/Columns/Link.php b/src/Services/Listings/Columns/Link.php new file mode 100644 index 000000000..40e5d1497 --- /dev/null +++ b/src/Services/Listings/Columns/Link.php @@ -0,0 +1,60 @@ +url = $urlFunction; + return $this; + } + + public function content(Closure|string $contentFunction): static + { + $this->content = $contentFunction; + return $this; + } + + public function shouldOpenInNewWindow(bool $shouldOpenInNewWindow = true): static + { + $this->targetBlank = $shouldOpenInNewWindow; + return $this; + } + + protected function getRenderValue(TwillModelContract $model): string + { + $url = null; + if (($urlFunction = $this->url) !== null) { + $url = $urlFunction($model); + } + + $content = null; + if (($contentFunction = $this->content) !== null) { + if (is_string($this->content)) { + $content = $this->content; + } else { + $content = $contentFunction($model); + } + } + + if ($url === null) { + return $content; + } + + return + 'targetBlank ? ' target="_blank"' : '') . '>' + . ($content ?? $url) + . ''; + } +}