I need help with the filemanager

I need help with the filemanager

by David Poly -
Number of replies: 2

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?

Average of ratings: -
In reply to David Poly

Re: I need help with the filemanager

by David Poly -

This is what I see when I choose the recent files tab, which indicates it is at least partially working. But the image location is wrong.

broken image icon in filemanager

In reply to David Poly

Re: I need help with the filemanager

by David Poly -
Wow, just kill me now. How can I be so blind. $default_values vs $defaultvalues... That's embarassing.