Hi,
What I am doing:
I am implementing a new question type using the "question type template" module. This sets up a standard interface - also with a general feedback html-editor option.
What I would like to do:
For the general feedback editor I would like to give the teacher the option to chose between the text- or html-editor just like it is implemented in the lesson module when adding a question page.
This means there should be a text-editor as standard for the general feedback. If the teacher wants to use the html-editor instead he/she needs to click onto the "Use editor" check-box. Since there is only one editor that should have this feature it would be nice to load the correct editor right away. If this is not possible a button "Refresh editor" may do the change.
What I have done so far:
So far I can display a separate Text-box similar to what I want using this code: (see my new question type module attached as .zip-file)
echo " [".get_string("useeditor", "qtype_so_sourcecode").": ". "<input type=\"checkbox\" name=\"useeditor\" value=\"1\" />";
helpbutton("so_generalfeedbackhint", get_string("useeditor", "qtype_so_sourcecode"), "qtype_so_sourcecode");
echo "]<br />\n";
print_textarea(false, 5, 70, 630, 300, "editor");
Asking for help:
1) How can I tell the generalfeedback-editor to display this option?
2) What do I have to implement in order to switch between both editors (with or without the "Refresh editor"-button)?
3) Will all the typed text parsed correct or do I have to take care of that? If I have to take care of that - how?
I really appreciate every feedback,
Süreç
What you describe seems to be already implemented in the Lesson module, where the question creator has a choice of displaying ordinary text box or the HTML editor (and must "redisplay page" to see it). Have you looked at it?
Joseph
Joseph
Hi Joseph,
great I got a response from you!
Yes, I came up to this idea because I had found it in the lesson module (strangely enough I can't see it anymore in any of my three installations and also not in the moodle demo). I tried adapting the code into my new module.
to my 1) question:
I found out that I can copy the "definition()"-function from "moodle\question\type\question_edit_form.php" into my "edit_so_sourcode_form.php" and make the changes directly where the generalfeedback textera has been added.
***********************
$mform->addElement('textarea', 'generalfeedback', get_string('generalfeedback', 'quiz'), array('rows' => 3, 'cols' => 57, 'course' => $COURSE->id));
$mform->setType('generalfeedback', PARAM_RAW);
$mform->setHelpButton('generalfeedback', array('generalfeedback', get_string('generalfeedback', 'quiz'), 'quiz'));
$mform->addElement('checkbox', 'useeditor', get_string('useeditor', 'qtype_so_sourcecode'));
$mform->setHelpButton('useeditor', array('so_useeditorhint', get_string('useeditor', 'qtype_so_sourcecode'), 'qtype_so_sourcecode'));
$refreshbutton = $mform->addElement('button', '', get_string('refresheditor', 'qtype_so_sourcecode' ));
$refreshbutton->updateAttributes(array( 'onclick' => "getElementById('editpage').redisplay.value=1;getElementById('editpage').submit()" )); //this is the part where it gets complicated in my eyes
**********************
For further implementation I would like to know though if there is a way to get away from the addElement-structure and adding the code like it is in my first post linking it to the generalfeedback part?
Can it be called a better coding-style to use only the addElement-structure then own displaying arrangements?
to my 2) question:
I found out that the main functionality behind the editor-refreshing-button can be seen in mod/lesson/action/updatepage.php
I thought it is a simple/easy step to start with the editor-choice since I once had tried putting functionality behind buttons and it was quiet easy. But in Moodle-code it looks more complex than I thought. Since this is not the most important requirement on my list I will leave it as a text-editor without being able to change it for now.
to my 3) question:
I guess and hope texts will be parsed correctly using updatepage.php like mentioned in question 2).
This is how it looks like now because I had to use the given Moodle structure:
great I got a response from you!
Yes, I came up to this idea because I had found it in the lesson module (strangely enough I can't see it anymore in any of my three installations and also not in the moodle demo). I tried adapting the code into my new module.
to my 1) question:
I found out that I can copy the "definition()"-function from "moodle\question\type\question_edit_form.php" into my "edit_so_sourcode_form.php" and make the changes directly where the generalfeedback textera has been added.
***********************
$mform->addElement('textarea', 'generalfeedback', get_string('generalfeedback', 'quiz'), array('rows' => 3, 'cols' => 57, 'course' => $COURSE->id));
$mform->setType('generalfeedback', PARAM_RAW);
$mform->setHelpButton('generalfeedback', array('generalfeedback', get_string('generalfeedback', 'quiz'), 'quiz'));
$mform->addElement('checkbox', 'useeditor', get_string('useeditor', 'qtype_so_sourcecode'));
$mform->setHelpButton('useeditor', array('so_useeditorhint', get_string('useeditor', 'qtype_so_sourcecode'), 'qtype_so_sourcecode'));
$refreshbutton = $mform->addElement('button', '', get_string('refresheditor', 'qtype_so_sourcecode' ));
$refreshbutton->updateAttributes(array( 'onclick' => "getElementById('editpage').redisplay.value=1;getElementById('editpage').submit()" )); //this is the part where it gets complicated in my eyes
**********************
For further implementation I would like to know though if there is a way to get away from the addElement-structure and adding the code like it is in my first post linking it to the generalfeedback part?
Can it be called a better coding-style to use only the addElement-structure then own displaying arrangements?
to my 2) question:
I found out that the main functionality behind the editor-refreshing-button can be seen in mod/lesson/action/updatepage.php
I thought it is a simple/easy step to start with the editor-choice since I once had tried putting functionality behind buttons and it was quiet easy. But in Moodle-code it looks more complex than I thought. Since this is not the most important requirement on my list I will leave it as a text-editor without being able to change it for now.
to my 3) question:
I guess and hope texts will be parsed correctly using updatepage.php like mentioned in question 2).
This is how it looks like now because I had to use the given Moodle structure:
Hi Süreç,
Unfortunately I cannot help you here, due to my limited knowledge of the inner workings of the quiz module. Tim Hunt is really the person who might help you.
Joseph
Unfortunately I cannot help you here, due to my limited knowledge of the inner workings of the quiz module. Tim Hunt is really the person who might help you.
Joseph
Hi Joseph,
oh, I see. I am new into forums and am not sure: do I have to send Tim Hunt an email-message or will he see this post anyway?
Thank you for help so far!
Süreç
oh, I see. I am new into forums and am not sure: do I have to send Tim Hunt an email-message or will he see this post anyway?
Thank you for help so far!
Süreç
I have read this thread. If your are reporting a bug, or suggesting a new feature that other people in the discussion agree with, then you should
1) Search the tracker to see if it is already recorded.
2) If not, add it.
That is the best way to ensure things are not forgotten about.
1) Search the tracker to see if it is already recorded.
2) If not, add it.
That is the best way to ensure things are not forgotten about.
Actually I am interested into getting answers to my questions at the bottom of to my 1 question:
For further implementation I would like to know though if there is a way to get away from the addElement-structure and adding the code like it is in my first post linking it to the generalfeedback part?
Can it be called a better coding-style to use only the addElement-structure then own displaying arrangements?
So I haven't found a bug or suggest a new feature but would like to know how to add simple html/php into the form without using the addElement-structure. Or I am asking if this is possible at all - if yes, how?
For further implementation I would like to know though if there is a way to get away from the addElement-structure and adding the code like it is in my first post linking it to the generalfeedback part?
Can it be called a better coding-style to use only the addElement-structure then own displaying arrangements?
So I haven't found a bug or suggest a new feature but would like to know how to add simple html/php into the form without using the addElement-structure. Or I am asking if this is possible at all - if yes, how?