X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/492ffff0a488d3bd9b3759686a037edf6190844b..refs/pull/4467/head:/app/Entities/Tools/PageEditorData.php diff --git a/app/Entities/Tools/PageEditorData.php b/app/Entities/Tools/PageEditorData.php index 3e1164175..3c7c9e2ea 100644 --- a/app/Entities/Tools/PageEditorData.php +++ b/app/Entities/Tools/PageEditorData.php @@ -2,6 +2,7 @@ namespace BookStack\Entities\Tools; +use BookStack\Activity\Tools\CommentTree; use BookStack\Entities\Models\Page; use BookStack\Entities\Repos\PageRepo; use BookStack\Entities\Tools\Markdown\HtmlToMarkdown; @@ -9,19 +10,14 @@ use BookStack\Entities\Tools\Markdown\MarkdownToHtml; class PageEditorData { - protected Page $page; - protected PageRepo $pageRepo; - protected string $requestedEditor; - protected array $viewData; protected array $warnings; - public function __construct(Page $page, PageRepo $pageRepo, string $requestedEditor) - { - $this->page = $page; - $this->pageRepo = $pageRepo; - $this->requestedEditor = $requestedEditor; - + public function __construct( + protected Page $page, + protected PageRepo $pageRepo, + protected string $requestedEditor + ) { $this->viewData = $this->build(); } @@ -69,6 +65,7 @@ class PageEditorData 'draftsEnabled' => $draftsEnabled, 'templates' => $templates, 'editor' => $editorType, + 'comments' => new CommentTree($page), ]; } @@ -94,10 +91,7 @@ class PageEditorData */ protected function getEditorType(Page $page): string { - $emptyPage = empty($page->html) && empty($page->markdown); - $pageType = (!empty($page->html) && empty($page->markdown)) ? 'wysiwyg' : 'markdown'; - $systemDefault = setting('app-editor') === 'wysiwyg' ? 'wysiwyg' : 'markdown'; - $editorType = $emptyPage ? $systemDefault : $pageType; + $editorType = $page->editor ?: self::getSystemDefaultEditor(); // Use requested editor if valid and if we have permission $requestedType = explode('-', $this->requestedEditor)[0]; @@ -108,4 +102,11 @@ class PageEditorData return $editorType; } -} \ No newline at end of file + /** + * Get the configured system default editor. + */ + public static function getSystemDefaultEditor(): string + { + return setting('app-editor') === 'markdown' ? 'markdown' : 'wysiwyg'; + } +}