The most complex file handling process takes place using the editor.
1. Loading the editor[muuda]
The editor can be loaded anywhere. First, we have to put a placeholder into the template and replace the placeholder by the content provided by the method buildWrapperForUpload in View. This method uses the template file upload.tpl and the part wrapper-for-uploading in it.
Inside the form for image, there is an iframe for the file browsing. The content of that iframe will be loaded by calling buildFormForUploading in the main controller. The actual content will be created by buildFormForUploading in View using upload.tpl and form-for-uploading in it.
2. Choosing a file to upload[muuda]
The content of the form will be submitted using uploadFile in the main controller. The actual upload takes place in uploadForPreview in FileHandler. It removes all the files and folders in final and original previews' folder, checks for the correct file and puts the file into the original previews' folder. Subsequently, the upload form is reloaded into iframe. Now, a real preview is needed and therefore, buildPreview from View uses the block preview from file.tpl for creation of a preview. setUploadFile loads the file into the preview block using the named buildPreview function. As a result, we see the uploaded file. If it is an image we see a thumbnail, otherwise a file icon.
3. Putting the uploaded file into the text[muuda]
There is a small icon for putting the file link or image into the text. A click on it calls insertFile in the main controller which calls insertInEditor in FileHandler to create another preview for the text. insertInEditor checks whether the file is there and the alternative text is set. buildFileInEditor creates the new preview file and puts it with the help of file-in-text in upload.tpl into the text according to whether it is an image or not.
4. Putting the files into final places[muuda]