Merge local and global crops for MediaPicker3 (#14237)

This commit is contained in:
Kenn Jacobsen
2023-05-15 10:06:24 +02:00
committed by GitHub
parent 368e9f2f59
commit 85d46c3e82
2 changed files with 205 additions and 77 deletions

View File

@@ -131,7 +131,16 @@ public class MediaPickerWithCropsValueConverter : PropertyValueConverterBase, ID
ApiMediaWithCrops ToApiMedia(MediaWithCrops media)
{
IApiMedia inner = _apiMediaBuilder.Build(media.Content);
return new ApiMediaWithCrops(inner, media.LocalCrops.FocalPoint, media.LocalCrops.Crops);
// make sure we merge crops and focal point defined at media level with the locally defined ones (local ones take precedence in case of a conflict)
ImageCropperValue? mediaCrops = media.Content.Value<ImageCropperValue>(_publishedValueFallback, Constants.Conventions.Media.File);
ImageCropperValue localCrops = media.LocalCrops;
if (mediaCrops != null)
{
localCrops = localCrops.Merge(mediaCrops);
}
return new ApiMediaWithCrops(inner, localCrops.FocalPoint, localCrops.Crops);
}
// NOTE: eventually we might implement this explicitly instead of piggybacking on the default object conversion. however, this only happens once per cache rebuild,