-
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
Get missing crops from configuration #6950
Conversation
@Shazwazza I somehow ruined #5739 when updating my local. Based on your comments on #5739 I took a look at ImageCropperValue and found a very simple solution. |
Hi there @cleversolutions, First of all: A big #H5YR for contributing to Umbraco during Hacktoberfest! We are very thankful for the huge amount of PRs submitted, and all the amazing work you've been doing 🥇 We have had another record breaking amount of PR's in both the CMS, Documentation, and other smaller public repositories. You can read all about the numbers in the Umbraco Hacktoberfest round-up blog post. Due to the amazing work you and others in the community have been doing, we've had a bit of a hard time keeping up. 😅 While all of the PRs for Hacktoberfest might not have been merged yet, you still qualify for receiving some Umbraco swag, congratulations! 🎉 In the spirit of Hacktoberfest we've prepared some exclusive Umbraco swag for all our contributors - including you! Receive your swag! 👈 Please follow this link to fill out and submit the form, before December 19th 2019. Following this date we'll be sending out all the swag, which also means that it might not reach your doorstep before February, so please bear with us and be patient 🙏 The only thing left to say is thank you so much for participating in Hacktoberfest! We really appreciate the help! Kind regards, |
@cleversolutions I can't reproduce this... see my comment here |
@kjac I can still reproduce the problem. I've replied to your comment #5737 (comment) with some screenshots. |
I can verify that after adding the first crop, you need to re-save the item with the 'Image Cropper' data type (used by default on the This is because the stored property value is a JSON version of Umbraco-CMS/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValue.cs Lines 155 to 192 in c63af8e
This PR ensures the crops from the configuration are used, by not short-circuiting and using an empty crop list instead. This means the Umbraco-CMS/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs Lines 29 to 53 in 23f8c3e
BTW: re-saving works, because the AngularJS controller adds the configured crops when the editor is loaded in the back-office: Lines 102 to 110 in bd26cb3
The Umbraco-CMS/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs Lines 35 to 55 in ef19633
|
@ronaldbarendse Thanks! as you mention:
This sounds like a breaking change in behavior to me, which we want to avoid. What do you suggest? |
@nul800sebastiaan This isn't a breaking change, as it's already correctly merging all configured crops when the saved crops aren't Because there's logic on the server and client-side that do the same thing, but just slightly different, this PR corrects that and is a really great bugfix (that should be included in the next release ASAP). |
I would suggest also removing the AngularJS logic for merging the configured crops BTW, as that's now redundant (it's already done in the editors |
I've tested the current behavior (version 8.6.1) a little bit more using the following Razor code on an SourceValue: @Json.Encode(image.GetProperty("umbracoFile").GetSourceValue())
ImageCropperValue: @Json.Encode(image.UmbracoFile)
Value: @Json.Encode(image.Value<string>("umbracoFile")) With zero configured crops, you can see the source value/saved data is already a JSON object containing an empty crops array (but this might be different on media created in older versions) and the string version is automatically converted to the image URL: SourceValue: "{\"src\":\"/media/yw3jcos3/test.png\",\"crops\":[]}"
ImageCropperValue: {"Src":"/media/yw3jcos3/test.png","FocalPoint":null,"Crops":[]}
Value: "/media/yw3jcos3/test.png" When this media item is opened in the back-office and saved, the focal point is added (and the saved data now also contains unnecessary white-space):
After adding the first 'Header' crop to the Image Cropper configuration, the
After saving the media item again, the crop is also added to the saved value (changing the configured crop dimensions won't change this value by now):
After removing the crop from the configuration, none of the values change, as the saved value is unaltered:
After saving the media item without any configured crops, it returns back to:
So it's clear the saved data can already differ based on the way it's added (or more specifically whether the value is set from the server of by the Image Cropper AngularJS code). There might be code that doesn't set the crops to an empty array (e.g. when created via the RTE, media picker or batch/folder upload), causing issue #5737. Besides this PR, I think we should make sure the following is also fixed:
|
Yikes! I thought I had long since merged this one, apologies for the delay @cleversolutions! All good! 👍 @ronaldbarendse Those updates sound good to me! |
👍 |
@cleversolutions Oh! I just noticed this is your first merged PR for Umbraco-CMS! 🎉 Congrats! You've earned your contrib badge on Our with this one as well: https://our.umbraco.com/members/cleversolutions 🏅 Great work, thanks again! |
Prerequisites
Replaces pull request #5739
Description
When you add a crop alias to Image Cropper after media already exists in your Media library it doesn't pick up any of the crops. This PR updates ImageCropperTemplateExtensions to check for this condition and configure crops from the DataType.Configuration.
Steps to reproduce
As per issue #5737
@product.Pho0tos.GetCropUrl("test")
Fixes #5737