Skip to content

Commit

Permalink
Updating preview URL on item saving.
Browse files Browse the repository at this point in the history
  • Loading branch information
parpalak committed Aug 12, 2024
1 parent 260197f commit f4c3560
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion _admin/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down
2 changes: 1 addition & 1 deletion _admin/templates/article/edit.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ $jsvarencode = static function ($var) {
</p>
<hr>
<p>
<a target="_blank" title="<?= $trans('Preview published') ?>" data-href="<?= $previewUrl ?>"
<a target="_blank" title="<?= $trans('Preview published') ?>"
href="<?= $previewUrl ?>" id="preview_link"><?= $trans('Preview ready') ?></a>
</p>
<?php endif; ?>
Expand Down
8 changes: 6 additions & 2 deletions _extensions/s2_blog/Admin/AdminConfigExtender.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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] : [],
Expand Down Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion _extensions/s2_blog/views/admin/post/edit.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ $jsvarencode = static function ($var) {
</p>
<hr>
<p>
<a target="_blank" title="<?= $trans('Preview published') ?>" data-href="<?= $previewUrl ?>" href="<?= $previewUrl ?>" id="preview_link"><?= $trans('Preview ready') ?></a>
<a target="_blank" title="<?= $trans('Preview published') ?>" href="<?= $previewUrl ?>" id="preview_link"><?= $trans('Preview ready') ?></a>
</p>
<?php endif; ?>
</div>
Expand Down
3 changes: 2 additions & 1 deletion _include/src/Admin/AdminConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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] : [],
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit f4c3560

Please sign in to comment.