I'm trying to add a placeholder image for different activities types (Similar to how a course has a thumbnail). I was able to add a file picker element to the mod_form and after submission, the db column has a random id. As for the next steps I want to display that image on the page but couldn't get it to work. Can someone please help me what to do since i can't make sense of the File API documentation
If you want a file to stay around, then you should use a File manager element instead.
With a file manager, you start by calling file_prepare_standard_filemanager() to copy files from the File API file area you've defined for storing your images, into a draft area for using with the form. You then display the form, which updates the files in the draft area. When the form is submitted, you call file_postupdate_standard_filemanager() to copy the files from the draft area back into the real file area you want to serve them from.
There's a lot more detail here: https://docs.moodle.org/dev/Using_the_File_API_in_Moodle_forms and there are a lot of examples of using the Files API throughout the Moodle code.
It might help to explain what you have figured out and where the problems are, rather than just a blanket "I can't make sense of the File API documentation", as that doesn't really give a good starting point for anyone to help you out.
Hi Davos, thanks for reaching out I haven't been using the functions you have mentioned since I based my plugin on mod_page. Can you point me to an activity that I can reference?
mod_resource / mod_folder have filemanager elements, although they are calling the draft file preparation code directly, rather than using the file_prepare_standard_filemanager + file_postupdate_standard_filemanager wrapper functions.
Have you tried searching the code for file_prepare_standard_filemanager? There are a good number of examples in Moodle core that use it.