public function onBeforeDeleteMedia(mixed $id, mixed $path, JModel $model) : bool

Fires before deleting a media file.


Description

Trigger hook to allow the plugins to make something before deleting one or more media files.

TIP: in case of failure while deleting the record, it is possible to throw an exception to abort the deleting process and return a readable error message. The same can be accomplished by registering an error to the model and returning false.

// throw an exception
throw new Exception('You are not authorised', 403);
// or register the error
$model->setError('You are not authorised');
return false;

Parameters

$id

(array|string)  Either the file name or an array of files to delete.

$path

(string|null)  An optional path from which the file should be deleted. If not specified, the default media folder will be used.

$model

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

Return Value

Boolean. Use false to abort the deleting process.


Example

/**
 * Trigger hook to allow the plugins to make something before
 * deleting one or more media files.
 *
 * @param   mixed    $id      Either the record ID or a list of records.
 * @param   mixed    $path    An optional path from which the file should be deleted.
 * @param   JModel   $model   The model instance.
 *
 * @return  boolean  False to abort the saving process.
 */
public function onBeforeDeleteMedia($id, $path, $model)
{
    /**
     * @todo do something before deleting the media file
     */

    return true;
}

Changelog

VersionDescription
1.7 Introduced.
Last Update: 2021-10-08 13:30
Helpful?
See Also: