From 97aeae935830ed8dae6347d75e0836ef1b9f38d2 Mon Sep 17 00:00:00 2001 From: payal-canyon Date: Wed, 9 Oct 2024 21:15:40 +0000 Subject: [PATCH] [AIDAPP-281]: fixed GDPR hyperlink issue --- .../Filament/Pages/ManagePortalSettings.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app-modules/portal/src/Filament/Pages/ManagePortalSettings.php b/app-modules/portal/src/Filament/Pages/ManagePortalSettings.php index bff723590..64834e693 100644 --- a/app-modules/portal/src/Filament/Pages/ManagePortalSettings.php +++ b/app-modules/portal/src/Filament/Pages/ManagePortalSettings.php @@ -220,4 +220,35 @@ public function form(Form $form): Form ->visible(fn (Get $get) => $get('knowledge_management_portal_enabled')), ]); } + + public function updateLinks(array $array): array + { + foreach ($array['content'] as &$paragraph) { + foreach ($paragraph['content'] as &$text) { + if (isset($text['marks'])) { + foreach ($text['marks'] as &$mark) { + if ($mark['type'] === 'link' && isset($mark['attrs']['href'])) { + if (strpos($mark['attrs']['href'], 'www.') === 0) { + $mark['attrs']['href'] = 'https://' . $mark['attrs']['href']; + } elseif (strpos($mark['attrs']['href'], 'http') !== 0) { + $mark['attrs']['href'] = 'https://' . $mark['attrs']['href']; + } + } + } + } + } + } + + return $array; + } + + protected function mutateFormDataBeforeSave(array $data): array + { + $tiptapContent = $data['gdpr_banner_text']; + $tiptapContent = $this->updateLinks($tiptapContent); + + $data['gdpr_banner_text'] = $tiptapContent; + + return $data; + } }