public function onRenderMedia(array $fileJModel $model) : string

Fires while rendering an unknown media type.


Description

Trigger hook to allow external plugins to implement a layout for their own media types. The media types are always rendered within the media manager.

The HTML supports 2 different blocks: one for the thumbnail and the other one for the preview, which must provide the inspector-only class.


Parameters

$file

(array)  An associative array holding some details of the file.

  • file - the full path of the file;
  • path - the directory in which the file is stored;
  • name - the file name (inclusive of extension);
  • file_ext - the file extension (dot included);
  • size - a readable file size, adjusted to the closest unit;
  • timestamp - the UNIX timestamp of the creation date;
  • creation - a readable creation date;
  • name_no_ext - the file name without the file extension;
  • uri - the full URI of the file;
  • width - the width (in pixel) of the file (for images only);
  • height - the height (in pixel) of the file (for images only).
$model

(JModel)  The model instance that handles the saving process.

Return Value

String. The HTML to display.


Example

/**
 * Trigger hook to allow external plugins to implement a layout for
 * their own media types.
 *
 * @param   array   $file   An array of file properties.
 * @param   JModel  $model  The model instance.
 *
 * @return  string  The resulting HTML.
 */
public function onRenderMedia($file, $model)
{
    if (preg_match("/\.(xml)$/", $file['name']))
    {
        // display a new icon for XML files
        return '<i class="fas fa-file-code" data-src="' . $file['uri'] .'"></i>';
    }
}

Changelog

VersionDescription
1.7 Introduced.
Last Update: 2021-10-08 13:55
Helpful?