You need to be logged in to post in the forum - Log In

An active JCE Pro Subscription is required to post in the forum - Buy a Subscription

Support is currently Offline

Official support hours
Monday to Friday
09:00 - 17:00 Europe/London (BST)

Please create a new Ticket and we will get back to you as soon as we can.

#108998 File Extension in media field in my own component

Posted in ‘Editor’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Latest post by teccrow on Friday, 08 October 2021 10:51 BST

teccrow
Hello, I have created my own component and use the form field in the backend:

<field
    name="file"
    type="media"
    label="COM_TOOLBOXHEKA_FIELD_FILE_LABEL"
    description="COM_TOOLBOXHEKA_FIELD_FILE_DESC"
    preview="false"
    class="span12"
    hint="text"
    accept="/image/downloads/"
    showon="type:1"
    />
In the JCE configuration I have activated both parameters in Profile > Plugin Settings > Media Field Options, so that when using the form field the JCE Media Browser is started and I can select or upload a file. But I can only select or upload files with the extension jpg, jpeg, png, apng, gif, webp, avif, although the extension pdf is entered in the JCE configuration > plugin settings > picture manager. In the global Joomla media configuration, PDF is also entered as a permitted file extension, image ending and file type. I know there is a hack where you can enter additional file types in com_media. But since this cannot be updated. I also read somewhere that the property should be added to the form field.

<field
    name="file"
    type="media"
    label="COM_TOOLBOXHEKA_FIELD_FILE_LABEL"
    description="COM_TOOLBOXHEKA_FIELD_FILE_DESC"
    preview="false"
    class="span12"
    hint="text"
    accept="/image/downloads/"
    showon="type:1"
    filter="pdf"
    />
But even then I cannot select or upload a PDF. Does anyone know a solution to this?

teccrow
Hello, I was able to solve my problem! Step 1: I copied the file 'plugins / system / jce / fields / mediajce.php' to 'administrator / components / com_mycomponent / models / fields' Step 2: Change my form field in:

<field
    name="file"
    type="mediajce"
    label="COM_TOOLBOXHEKA_FIELD_FILE_LABEL"
    description="COM_TOOLBOXHEKA_FIELD_FILE_DESC"
    preview="false"
    class="span12"
    directory="/image/downloads/"
    showon="type:1"
    />
Now the media field is not an image manager but a file manager and can be set via the profile in the JCE configuration.

Ryan
You can set specific filetypes for a mediajce field by using a mediatype attribute, eg:

<field
    name="file"
    type="mediajce"
    label="COM_TOOLBOXHEKA_FIELD_FILE_LABEL"
    description="COM_TOOLBOXHEKA_FIELD_FILE_DESC"
    preview="false"
    class="span12"
    directory="/image/downloads/"
    showon="type:1"
    mediatype="files"
    />
Unfortunately this does not work for a core "media" field. In a similar way to what you have done for the mediajce.php field, you can create an override of the Joomla core media field, and change the url in that field so that the view=images part becomes view=files. See this post - https://www.joomlacontenteditor.net/support/forum/108490#p108496

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

teccrow
Sorry, I forgot to write that I changed the file 'administrator / components / com_mycomponent / models / fields / mediajce.php':

public function setup(SimpleXMLElement $element, $value, $group = null)
{
    $result = parent::setup($element, $value, $group);

    if ($result === true) {
        //$this->mediatype = isset($this->element['mediatype']) ? (string) $this->element['mediatype'] : 'images';
        $this->mediatype = "files";
     }

     return $result;
 }
This is how it works very well in my component!