From 6796f516d393c491ea078c6fbac7b56ececdb333 Mon Sep 17 00:00:00 2001 From: Avinash Kumar Date: Mon, 18 Sep 2023 02:17:32 +0530 Subject: [PATCH 1/3] parseInternalLinks corrections for double digit ids --- src/TwillUtil.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/TwillUtil.php b/src/TwillUtil.php index aa45ffb5d..f0b1a062b 100644 --- a/src/TwillUtil.php +++ b/src/TwillUtil.php @@ -57,13 +57,18 @@ public function clearTempStore(): void public function parseInternalLinks(string $content): string { return preg_replace_callback( - '/(#twillInternalLink::(.*)#(\d))/', + '/(#twillInternalLink::(.*)#(\d+))/', function (array $data) { if (isset($data[2], $data[3])) { $modelClass = $data[2]; $id = $data[3]; $model = $modelClass::published()->where('id', $id)->first(); + + if (!$model) { + return url('404'); + } + if ($model instanceof TwillLinkableModel) { return $model->getFullUrl(); } From 33123423a30919ca46d7a04e20c23715913a1899 Mon Sep 17 00:00:00 2001 From: Avinash Kumar Date: Mon, 18 Sep 2023 02:35:19 +0530 Subject: [PATCH 2/3] multiple # presence handling in single block --- src/TwillUtil.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TwillUtil.php b/src/TwillUtil.php index f0b1a062b..689eba953 100644 --- a/src/TwillUtil.php +++ b/src/TwillUtil.php @@ -57,7 +57,7 @@ public function clearTempStore(): void public function parseInternalLinks(string $content): string { return preg_replace_callback( - '/(#twillInternalLink::(.*)#(\d+))/', + '/(#twillInternalLink::(.*?)#(\d+))/', function (array $data) { if (isset($data[2], $data[3])) { $modelClass = $data[2]; From 5df8581bfb8938a1b824591b46b4cee80e4e98e1 Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Wed, 24 Jan 2024 01:21:47 +0100 Subject: [PATCH 3/3] Support models with a defined morphmaps in WYSIWYG link browser rendering helper --- src/TwillUtil.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/TwillUtil.php b/src/TwillUtil.php index 689eba953..cb93efe35 100644 --- a/src/TwillUtil.php +++ b/src/TwillUtil.php @@ -3,6 +3,7 @@ namespace A17\Twill; use A17\Twill\Models\Contracts\TwillLinkableModel; +use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Facades\Session; /** @@ -63,6 +64,10 @@ function (array $data) { $modelClass = $data[2]; $id = $data[3]; + if (array_key_exists($modelClass, Relation::morphMap())) { + $modelClass = Relation::morphMap()[$modelClass]; + } + $model = $modelClass::published()->where('id', $id)->first(); if (!$model) {