From f4c356011d621da5616ea4ef1e779ee1ffd7ff45 Mon Sep 17 00:00:00 2001 From: Roman Parpalak Date: Mon, 12 Aug 2024 21:02:34 +0300 Subject: [PATCH] Updating preview URL on item saving. --- _admin/js/editor.js | 2 +- _admin/templates/article/edit.php.inc | 2 +- _extensions/s2_blog/Admin/AdminConfigExtender.php | 8 ++++++-- _extensions/s2_blog/views/admin/post/edit.php.inc | 2 +- _include/src/Admin/AdminConfigProvider.php | 3 ++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/_admin/js/editor.js b/_admin/js/editor.js index e9644e9..adb11f3 100644 --- a/_admin/js/editor.js +++ b/_admin/js/editor.js @@ -81,7 +81,7 @@ function initArticleEditForm(eForm, statusData, sEntityName, sTextareaName) { eForm.querySelector('.field-published').setAttribute('data-published-status', isPublished ? '1' : '0'); const ePreviewLink = eForm.querySelector('#preview_link'); - ePreviewLink.href = ePreviewLink.getAttribute('data-href').replace(/\/[^\/]*$/, '/') + encodeURIComponent(eForm.elements['url'].value); + ePreviewLink.href = statusData['url']; ePreviewLink.style.display = isPublished ? 'inline' : 'none'; } diff --git a/_admin/templates/article/edit.php.inc b/_admin/templates/article/edit.php.inc index 37c9419..a2ca51c 100644 --- a/_admin/templates/article/edit.php.inc +++ b/_admin/templates/article/edit.php.inc @@ -166,7 +166,7 @@ $jsvarencode = static function ($var) {


-

diff --git a/_extensions/s2_blog/Admin/AdminConfigExtender.php b/_extensions/s2_blog/Admin/AdminConfigExtender.php index b8fdc2d..46687bd 100644 --- a/_extensions/s2_blog/Admin/AdminConfigExtender.php +++ b/_extensions/s2_blog/Admin/AdminConfigExtender.php @@ -23,7 +23,6 @@ use S2\AdminYard\Database\LogicalExpression; use S2\AdminYard\Event\AfterLoadEvent; use S2\AdminYard\Event\AfterSaveEvent; -use S2\AdminYard\Event\BeforeDeleteEvent; use S2\AdminYard\Event\BeforeRenderEvent; use S2\AdminYard\Event\BeforeSaveEvent; use S2\AdminYard\Translator; @@ -35,6 +34,7 @@ use S2\Cms\Admin\Event\VisibleEntityChangedEvent; use S2\Cms\Model\PermissionChecker; use S2\Cms\Model\TagsProvider; +use S2\Cms\Pdo\DbLayerException; use S2\Cms\Template\HtmlTemplateProvider; use s2_extensions\s2_blog\BlogUrlBuilder; use s2_extensions\s2_blog\Model\BlogCommentNotifier; @@ -328,7 +328,7 @@ public function extend(AdminConfig $adminConfig): void label: $this->translator->trans('Author'), type: new DbColumnFieldType(FieldConfig::DATA_TYPE_INT, defaultValue: $this->permissionChecker->getUserId()), control: 'select', - linkToEntity: new LinkTo($adminConfig->findEntityByName('User'), 'CASE WHEN name IS NULL OR name = \'\' THEN login ELSE name END', new LogicalExpression('create_articles', 1)), + linkToEntity: new LinkTo($adminConfig->findEntityByName('User'), 'CASE WHEN name IS NULL OR name = \'\' THEN login ELSE name END'), useOnActions: [ FieldConfig::ACTION_LIST, ...$this->permissionChecker->isGranted(PermissionChecker::PERMISSION_EDIT_SITE) ? [FieldConfig::ACTION_EDIT] : [], @@ -562,11 +562,15 @@ public function extend(AdminConfig $adminConfig): void ; } + /** + * @throws DbLayerException + */ private function getPostStatusData(int $createTime, string $url): array { $urlStatus = $this->postProvider->checkUrlStatus($createTime, $url); return [ + 'url' => $this->blogUrlBuilder->postFromTimestamp($createTime, $url), 'urlStatus' => $urlStatus, 'urlTitle' => match ($urlStatus) { 'empty' => $this->translator->trans('URL empty'), diff --git a/_extensions/s2_blog/views/admin/post/edit.php.inc b/_extensions/s2_blog/views/admin/post/edit.php.inc index e477e2f..7134414 100644 --- a/_extensions/s2_blog/views/admin/post/edit.php.inc +++ b/_extensions/s2_blog/views/admin/post/edit.php.inc @@ -156,7 +156,7 @@ $jsvarencode = static function ($var) {


- +

diff --git a/_include/src/Admin/AdminConfigProvider.php b/_include/src/Admin/AdminConfigProvider.php index 8b42259..116615d 100644 --- a/_include/src/Admin/AdminConfigProvider.php +++ b/_include/src/Admin/AdminConfigProvider.php @@ -549,7 +549,7 @@ function (BeforeSaveEvent $event) { label: $this->translator->trans('Author'), type: new DbColumnFieldType(FieldConfig::DATA_TYPE_INT), control: 'select', - linkToEntity: new LinkTo($userEntity, 'CASE WHEN name IS NULL OR name = \'\' THEN login ELSE name END', new LogicalExpression('create_articles', 1)), + linkToEntity: new LinkTo($userEntity, 'CASE WHEN name IS NULL OR name = \'\' THEN login ELSE name END'), useOnActions: [ FieldConfig::ACTION_LIST, ...$this->permissionChecker->isGranted(PermissionChecker::PERMISSION_EDIT_SITE) ? [FieldConfig::ACTION_EDIT] : [], @@ -970,6 +970,7 @@ private function getArticleStatusData(int $articleId): array [$urlStatus, $templateStatus] = $this->articleProvider->checkUrlAndTemplateStatus($articleId); return [ + 'url' => $this->articleProvider->pathFromId($articleId), 'urlStatus' => $urlStatus, 'urlTitle' => match ($urlStatus) { 'empty' => $this->translator->trans('URL empty'),