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.
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;
});
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);
Set First Photo Upload as Logo
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