Hi,
I am new in working with moodle and I hope I can get some help here.
I'm trying to add a text editor in the moodle form (mediathek/mod_form.php)
The old code that I had looked like this:
/// Adding the required "summary" field to hold the description of the instance
$mform->addElement('htmleditor', 'summary', get_string('mediatheksummary', 'mediathek'));
$mform->setType('summary', PARAM_RAW);
$mform->addHelpButton('summary', 'mediatheksummary', 'mediathek');
I changed the deprecated htmleditor to editor but since then the changes that I write into the editor wont be saved. I followed the instructions here.
/// Adding the required "summary" field to hold the description of the instanceI am aware of the this post and im stuck at the same point but I didn't get it to work.
$textfieldoptions = array('trusttext'=>true, 'subdirs'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>null, 'context'=>null);
$mform->addElement('editor', 'summary', get_string('mediatheksummary', 'mediathek'), null, $textfieldoptions);
$mform->setType('summary', PARAM_RAW);
$mform->addHelpButton('summary', 'mediatheksummary', 'mediathek');
$data = file_prepare_standard_editor($data, 'textfield', $textfieldoptions, $context=null, 'mod_mediathek', 'filearea', $itemid=null);
$data = file_postupdate_standard_editor($data, 'textfield', $textfieldoptions, $context, 'mod_mediathek', 'filearea', $itemid=null);
The same problem seems to be in this here but unfortunatelly that also didn't have any solution.
I also already tried looking into others like mod/page/mod_form.php
I followed 1-3 but like on the other threads im stuck in the steps 4 and 5.
Where should I put that code? Inside the mod_form.php? Does it have to be inside a particular function (like validation(), data_preprocessing()...)?
What's the "data" variable and where do I get it from?
- name database fields: textfield, textfieldformat (and textfieldtrust if required)
- create options array. note that context is the best, most local context you have available.
$textfieldoptions = array('trusttext'=>true, 'subdirs'=>true, 'maxfiles'=>$maxfiles,
'maxbytes'=>$maxbytes, 'context'=>$context); - add editor textfield_editorto moodle form, pass options through custom data in form constructor, set $data->id to null if data not exist yet
$mform->addElement('editor', 'textfield_editor', get_string('fieldname', 'somemodule'),
null, $textfieldoptions); - prepare data
$data = file_prepare_standard_editor($data, 'textfield', $textfieldoptions, $context,
'mod_somemodule', 'somearea', $data->id); - get submitted data and after inserting/updating of data
$data = file_postupdate_standard_editor($data, 'textfield', $textfieldoptions, $context,
'mod_somemodule', 'somearea', $data->id);
max