I wrote a component and need a field there where the user can pick a pdf from the media manager. When I set the field-type in the field list to «media», the media-manager only shows images.
How do I make it show all files instead of images only?
I have not tested this in later Joomla versions, but at least in 2.5.x it was possible to display a list of files in a folder in the form of the drop-down.
The path is hardcoded and rather limited , BUT for some use cases it may just do the trick and provide the flexibility needed.
Ladies and gentleman, presenting the filelist
:
<field
name="yourfile"
type="filelist"
label="COM_EXAMPLE_FIELD_YOURFILE_LABEL"
description="COM_EXAMPLE_FIELD_YOURFILE_DESC"
directory="media/com_example/files/"
hide_none="true"
hide_default="true"
/>
In case anyone is still interested, I've described a solution here, where a plug-in is used to override the imageslist view of com_media so that it shows all files in the media manager. I've put the code on GitHub.
I'd be first to admit that this is a less than elegant solution, but it works for the project I developed it for. I would treat this code as a starting point for your project, not a polished solution.
Extending on the suggestion by @ValentinDespa, you can use the filelist
form field type, and add a filter
parameter. Any regular expression can be added here, see example below for how to filter PDF-files only.
<field type="filelist" name="pdf" label="Select PDF" directory="images" filter="\.pdf$"/>
This works fine in Joomla 3.x, BTW.
The Media form field type is used to select an image. So it filters out other files. Have a look at Joomla documentation for the available standard form fields types. You might also want to consider to create your own custom modal form field type for your component.
You can use JCE editor with plugin file manager.
https://www.joomlacontenteditor.net/downloads/plugins/file-manager