1212use BookStack \Entities \Tools \BookContents ;
1313use BookStack \Entities \Tools \PageContent ;
1414use BookStack \Entities \Tools \PageEditorData ;
15+ use BookStack \Entities \Tools \PageEditorType ;
1516use BookStack \Entities \Tools \TrashCan ;
1617use BookStack \Exceptions \MoveOperationException ;
1718use BookStack \Exceptions \PermissionsException ;
@@ -127,7 +128,9 @@ protected function updateTemplateStatusAndContentFromInput(Page $page, array $in
127128 }
128129
129130 $ pageContent = new PageContent ($ page );
130- $ currentEditor = $ page ->editor ?: PageEditorData::getSystemDefaultEditor ();
131+ $ defaultEditor = PageEditorType::getSystemDefault ();
132+ $ currentEditor = PageEditorType::forPage ($ page ) ?: $ defaultEditor ;
133+ $ inputEditor = PageEditorType::fromRequestValue ($ input ['editor ' ] ?? '' ) ?? $ currentEditor ;
131134 $ newEditor = $ currentEditor ;
132135
133136 $ haveInput = isset ($ input ['markdown ' ]) || isset ($ input ['html ' ]);
@@ -136,15 +139,15 @@ protected function updateTemplateStatusAndContentFromInput(Page $page, array $in
136139 if ($ haveInput && $ inputEmpty ) {
137140 $ pageContent ->setNewHTML ('' , user ());
138141 } elseif (!empty ($ input ['markdown ' ]) && is_string ($ input ['markdown ' ])) {
139- $ newEditor = ' markdown ' ;
142+ $ newEditor = PageEditorType::Markdown ;
140143 $ pageContent ->setNewMarkdown ($ input ['markdown ' ], user ());
141144 } elseif (isset ($ input ['html ' ])) {
142- $ newEditor = ' wysiwyg ' ;
145+ $ newEditor = ( $ inputEditor -> isHtmlBased () ? $ inputEditor : null ) ?? ( $ defaultEditor -> isHtmlBased () ? $ defaultEditor : null ) ?? PageEditorType::WysiwygTinymce ;
143146 $ pageContent ->setNewHTML ($ input ['html ' ], user ());
144147 }
145148
146149 if ($ newEditor !== $ currentEditor && userCan ('editor-change ' )) {
147- $ page ->editor = $ newEditor ;
150+ $ page ->editor = $ newEditor-> value ;
148151 }
149152 }
150153
0 commit comments