The last time I used Ditto I think it hadn't even hit 0.5 and I know there have been some serious changes since then.
Let's say I have a node that has a standard Umbraco Image Cropper against it, is there anything out of the box that will allow me to handle the mapping or do I need a custom Type Converter / Value Resolver?
If a custom converter is required could you please give me an example?
Hi Lee, thanks for the response. So how do I go about using the value converter?
I have a 'section' document type which has the two image cropper properties 'sectionImageOne' and 'sectionImageTwo' and then on my model I have those two as properties of type 'ImageCropDataSet'. What do I do to tell Ditto to use that converter?
If you add the ImageCropperPropertyConverter class in your code (and compile), then Umbraco will pick it up and give the correct type to Ditto. No other attributes need to be declared.
Hmm I've done that and get a null exception when ditto tries to do the mapping in my hijack controller. Everything works when I comment out those two 'ImageCropDataSet' properties on my model.
Maybe it's worth noting that I haven't defined any crops for the image cropper and some of the croppers haven't yet had an image added to them. At the moment I mainly want to use the cropper to get the focal point stuff and then manipulate the crops using querystring parameters.
Ok, so I added a square 300 x 300 crop to the image cropper and it works now. Would it not be possible for it to work without any crops defined as in my case I'm using the cropper for the ability to set a focal point although I guess in future I may set predefined crops against the image. It just seems annoying to have to set one now as that 300px crop is never gonna get used
GetCropUrl() relies on having an alias so we can't do anything about that. The only url available to you without one will be the ImageCropDataSet.Src property
Getting back up to speed with Ditto
Hi Lee,
The last time I used Ditto I think it hadn't even hit 0.5 and I know there have been some serious changes since then.
Let's say I have a node that has a standard Umbraco Image Cropper against it, is there anything out of the box that will allow me to handle the mapping or do I need a custom Type Converter / Value Resolver?
If a custom converter is required could you please give me an example?
Cheers, Martin
Hi Martin,
Sure, see this thread:
https://our.umbraco.org/projects/developer-tools/ditto/ditto-feedback/66353-imagecropper-mapping-with-ditto#comment-221601
We have a unit-test that supports this:
https://github.com/leekelleher/umbraco-ditto/blob/master/tests/Our.Umbraco.Ditto.Tests/ImageCropDataSetMappingTests.cs
But it does need the
ImageCropperPropertyConverter
that Jeavon provides in the comments of the above thread.Cheers,
- Lee
Hey Lee, Just to note as of Umbraco 7.4.3 I think the
ImageCropperPropertyConverter
exists in CoreYou're right! It got added in v7.4.0,
ImageCropperValueConverter
. #TIL ;-)Cheers,
- Lee
Nice! I just removed the converter from my solution and everything still works :))
Cool! Glad that it worked out. Do you still need to save the crop first though? (just asking for future reference)
Hi Lee, thanks for the response. So how do I go about using the value converter?
I have a 'section' document type which has the two image cropper properties 'sectionImageOne' and 'sectionImageTwo' and then on my model I have those two as properties of type 'ImageCropDataSet'. What do I do to tell Ditto to use that converter?
Martin
If you add the
ImageCropperPropertyConverter
class in your code (and compile), then Umbraco will pick it up and give the correct type to Ditto. No other attributes need to be declared.Hmm I've done that and get a null exception when ditto tries to do the mapping in my hijack controller. Everything works when I comment out those two 'ImageCropDataSet' properties on my model.
Maybe it's worth noting that I haven't defined any crops for the image cropper and some of the croppers haven't yet had an image added to them. At the moment I mainly want to use the cropper to get the focal point stuff and then manipulate the crops using querystring parameters.
Ok, so I added a square 300 x 300 crop to the image cropper and it works now. Would it not be possible for it to work without any crops defined as in my case I'm using the cropper for the ability to set a focal point although I guess in future I may set predefined crops against the image. It just seems annoying to have to set one now as that 300px crop is never gonna get used
Hi Martin,
GetCropUrl()
relies on having an alias so we can't do anything about that. The only url available to you without one will be theImageCropDataSet.Src
propertyCheers James
is working on a reply...