I'm having a hard time setting up the file manager in a plugin I'm working on. The File API documentation lead me nowhere so I checked the code of the assign module as a starting point but something's still missing.
Everything in mdl_files is saved correctly, I checked this against the assign module, it's identical in data saved.
in the mod_form.php file, is use:
function data_preprocessing(&$default_values) {
...
$draftitemid = file_get_submitted_draft_itemid('testattachment');
file_prepare_draft_area($draftitemid, $this->context->id, 'mod_mymod', 'testattachment', 0);
$defaultvalues['testattachment'] = $draftitemid;
}
And in lib.php:
function mymod_update_instance($data, $mform = null) {
...
$context = context_module::instance($data->coursemodule);
$draftitemid = file_get_submitted_draft_itemid('testattachment');
file_save_draft_area_files($draftitemid, $context->id, 'mod_mymod', 'testattachment', 0);
}
But it's not working, the filearea isn't being populated in the form and if I check the recent files of that same filearea, I have my previously uploaded file with a broken image icon.
I believe the link should be pointing towards "/moodle/draftfile.php/5/user/draft/227600098/mypic.png"
but instead is pointing towards "/moodle/pluginfile.php/128/mod_mymod/testattachment/mypic.png"
I think I might have the context set wrong but I triple checked everything and I can't see where.
Can anyone shed some light on this for me?