From 61ec1e4c357be322311c63346e39e3b7c19c0f78 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 20 Mar 2014 14:58:18 +1100 Subject: [PATCH] Fixes the Url property to work with the image cropper to be consistent with the upload field. --- .../Models/PublishedContentBase.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web/Models/PublishedContentBase.cs b/src/Umbraco.Web/Models/PublishedContentBase.cs index 2ca1978c29..aa801fbe2f 100644 --- a/src/Umbraco.Web/Models/PublishedContentBase.cs +++ b/src/Umbraco.Web/Models/PublishedContentBase.cs @@ -47,7 +47,30 @@ namespace Umbraco.Web.Models var prop = GetProperty(Constants.Conventions.Media.File); if (prop == null) throw new NotSupportedException("Cannot resolve a Url for a media item when there is no 'umbracoFile' property defined."); - _url = prop.Value.ToString(); + + if (prop.Value == null) + { + _url = string.Empty; + return _url; + } + + var propType = ContentType.GetPropertyType(Constants.Conventions.Media.File); + + //This is a hack - since we now have 2 properties that support a URL: upload and cropper, we need to detect this since we always + // want to return the normal URL and the cropper stores data as json + switch (propType.PropertyEditorAlias) + { + case Constants.PropertyEditors.UploadFieldAlias: + _url = prop.Value.ToString(); + break; + case Constants.PropertyEditors.ImageCropperAlias: + //get the url from the json format + var val = prop.Value.ToString(); + var crops = val.SerializeToCropDataSet(); + _url = crops != null ? crops.Src : string.Empty; + break; + } + break; default: throw new NotSupportedException();