@@ -63,6 +63,13 @@ public function addDataAndToggleButton(Doku_Event $event, $param)
6363 return ;
6464 }
6565
66+ /** @var Doku_Form|\dokuwiki\Form\Form $form */
67+ $ form = $ event ->data ;
68+
69+ // return early if content is not editable
70+ if ($ this ->isReadOnly ($ form )) return ;
71+
72+
6673 $ useWYSIWYG = get_doku_pref ('plugin_prosemirror_useWYSIWYG ' , false );
6774
6875 $ prosemirrorJSON = '' ;
@@ -85,16 +92,13 @@ public function addDataAndToggleButton(Doku_Event $event, $param)
8592 }
8693 }
8794
88- /** @var Doku_Form|\dokuwiki\Form\Form $form */
89- $ form = $ event ->data ;
90-
91- if (is_a ($ form , \dokuwiki \Form \Form::class)) {
92- $ form ->addElement ($ this ->buildToggleButton ());
95+ if (is_a ($ form , \dokuwiki \Form \Form::class)) {
96+ $ form ->addElement ($ this ->buildToggleButton (), 0 );
9397 $ form ->setHiddenField ('prosemirror_json ' ,$ prosemirrorJSON );
9498 $ form ->addHTML ('<div class="prosemirror_wrapper" id="prosemirror__editor"></div> ' , 1 );
9599 } else {
96100 // todo remove when old stable is no longer supported
97- $ form ->addElement ( $ this ->buildOldToggleButton ());
101+ $ form ->insertElement ( 0 , $ this ->buildOldToggleButton ());
98102 $ form ->addHidden ('prosemirror_json ' ,$ prosemirrorJSON );
99103 $ form ->insertElement (1 , '<div class="prosemirror_wrapper" id="prosemirror__editor"></div> ' );
100104 }
@@ -106,7 +110,7 @@ public function addDataAndToggleButton(Doku_Event $event, $param)
106110 * Creates it as hidden if forcing WYSIWYG
107111 *
108112 * @deprecated use buildToggleButton instead
109- * @return array the pseudo-tag expected by \Doku_Form::addElement
113+ * @return array the pseudo-tag expected by \Doku_Form::insertElement
110114 */
111115 protected function buildOldToggleButton ()
112116 {
@@ -322,6 +326,27 @@ public function addJSINFO()
322326 global $ JSINFO ;
323327 $ JSINFO ['SMILEY_CONF ' ] = getSmileys ();
324328 }
329+
330+ /**
331+ * Returns true if the current content is read only
332+ *
333+ * @todo remove Doku_Form case when the class is removed
334+ *
335+ * @param $form
336+ * @return bool
337+ */
338+ protected function isReadOnly ($ form )
339+ {
340+ if (is_a ($ form , \dokuwiki \Form \Form::class)) {
341+ $ textareaPos = $ form ->findPositionByType ('textarea ' );
342+ $ readonly = $ textareaPos !== false && !empty ($ form ->getElementAt ($ textareaPos )->attr ('readonly ' ));
343+ } else {
344+ /** @var Doku_Form $form */
345+ $ textareaPos = $ form ->findElementByType ('wikitext ' );
346+ $ readonly = $ textareaPos !== false && !empty ($ form ->getElementAt ($ textareaPos )['readonly ' ]);
347+ }
348+ return $ readonly ;
349+ }
325350}
326351
327352// vim:ts=4:sw=4:et:
0 commit comments