-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements to media pickers/crop handling and URL generation #10529
Improvements to media pickers/crop handling and URL generation #10529
Conversation
Alias = configuredCrop.Alias, | ||
Width = configuredCrop.Width, | ||
Height = configuredCrop.Height, | ||
Coordinates = crop?.Coordinates |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The coordinates are actually the only data we need to store for a crop (together with the alias). We could reduce the size of all stored crop data by removing the width and height!
|
||
imageCropperValue.Crops = crops; | ||
|
||
if (configuration?.EnableLocalFocalPoint == false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to check for this configuration setting, as the picker always stores the default focal point (0.5, 0.5). Removing this together with the crop width/height would also reduce the size of data stored!
|
||
localCrops.ApplyConfiguration(configuration); | ||
|
||
// TODO: This should be optimized/cached, as calling Activator.CreateInstance is slow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added this to-do, because it's also something that's done in the BlockListPropertyValueConverter
and might have considerable performance gains by using similar techniques as in PublishedModelFactory
(caching emitted constructor functions using ReflectionUtilities
). Maybe @Shazwazza can give some pointers on how to best handle/implement this?
I've created an overview of the changes in this PR, as it contains some breaking and functional changes. These should all be very minimal (or not noticeable at all if you're upgrading from pre 8.14): Breaking changes:
Functional changes:
We should make sure to also update the documentation for 8.15: https://our.umbraco.com/Documentation/Fundamentals/Backoffice/property-editors/built-in-property-editors/Media-Picker-3/ |
Prerequisites
If there's an existing issue for this PR then this fixes #10308, #10402 and #10397.
Description
Building upon PR #10517 that introduces backwards compatibility for the stored data format between
Media Picker (legacy)
(v2) and the newMedia Picker
(v3), this PR adds compatibility to the returned models on the front-end (and includes some additional improvements).Model compatibility with
IPublishedContent
This compatibility is added by making
MediaWithCrops
inherit fromPublishedContentWrapped
, making it anIPublishedContent
instance again, so the following Razor/view code won't break by switching to the new picker:One thing to note though: the concrete implementation of the
IPublishedContent
will change toMediaWithCrops<T>
, so you can't cast directly to the Models Builder generated model (e.g.var image = (Image)Model.Image
will still break). If you want the concrete media item model, you can either cast the 'wrapped' content toImage
or better yet, cast toMediaWithCrops<Image>
and access it using the newContent
property:New
GetCropUrl()
extension methodsUsing local crops (defined on the Media Picker data type) together with media crops (defined on the Image Cropper data type) wasn't yet possible, so you'd have to ensure you're using the correct crops and aliases. This PR now merges local crops with the media ones, so the calling code can be the same for local and media crops:
In short: if the local crops doesn't contain the crop alias, it will look in the media crops. Also, if you have the focal point disabled on the Media Picker, it will fall-back to the global focal point (on the media item/Image Cropper).
Only return configured crops in the model
Because the stored data contains all crop information (as JSON), removing a crop from the configuration didn't remove existing crops from the returned model. A previous PR (#6950) already added missing crops (not in the stored data, but later added to the configuration), but because removing a local crop should now fall-back to the media crops, this caused a problem. This PR ensures crops removed from the configuration (either local crops on the Media Picker or media crops on the Image Cropper) are not returned in the model anymore, making sure you can't use outdated crops on the front-end.
I'll make sure to add some comments to the code, as it might be quite a lot to go though 😇