JReviews logo Docs
Menu
Version

jreviews:media.data_before_save

Allows filtering and modifying media data array before it's saved to database. Useful for automated media processing and metadata manipulation.

Filter
Media
Since 6.0.0

You need to have a working knowledge of Hooks before you get started.

Fires when uploading new media to a listing, before data is written to database

Parameters

Name Type Description
$mediaData array The media data array to be saved
$listing \JReviews\App\Models\Listing The listing this media belongs to
$user \JReviews\App\Models\User The user uploading the media

Boilerplate Code

Use the boilerplate code to start using the filter, and add your own logic to modify the first argument and return it.

fwd_add_filter('jreviews:media.data_before_save', function($mediaData, $listing, $user)
{
    // Your code here
    
    return $mediaData;
});
Development & Support
Customizations are not included with support. We provide this information to make it easier for developers to extend the functionality. From time to time we may have some availability for custom work. Get in touch to see if there's an opportunity to work together.

Examples

Set First Photo Upload as Cover

Using the knowledge that the first photo is automatically set as the main media, check if the uploaded media has been set as the main media and then also set it as cover.

fwd_add_filter('jreviews:media.data_before_save', function($mediaData, $listing, $user)
{
    if ($mediaData['main_media'] == 1) {
        $mediaData['media_function'] = 'cover';
    }

    return $mediaData;
}, 10, 3);

Using the knowledge that the first photo is automatically set as the main media, check if the uploaded media has been set as the main media and then also set it as logo.

fwd_add_filter('jreviews:media.data_before_save', function($mediaData, $listing, $user)
{
    if ($mediaData['main_media'] == 1) {
        $mediaData['media_function'] = 'logo';
    }

    return $mediaData;
}, 10, 3);

Source Files

  • app/Actions/StoreListingMediaAction.php