public function onBeforeRenameMedia(string &$new, string $prev, JModel $model) : bool

Fires before renaming a media file.


Description

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

TIP: in case of failure while saving the record, it is possible to throw an exception to abort the saving 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('Invalid name', 500);
// or register the error
$model->setError('Invalid name');
return false;

Parameters

&$new

(string)  The new file name.

$prev

(string)  The current file name.

$model

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

Return Value

Boolean. Use false to abort the renaming process.


Example

/**
 * Trigger event to allow the plugins to make something before
 * renaming one or more media files.
 *
 * @param   string   &$new   The new file name.
 * @param   string   $prev   The current file name.
 * @param   JModel   $model  The model instance.
 *
 * @return  boolean  False to abort the saving process.
 */
public function onBeforeRenameMedia(&$new, $prev, $model)
{
    /**
     * @todo do something before renaming the media file
     */

    return true;
}

Changelog

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