diff --git a/src/Umbraco.Core/PublishedContentHelper.cs b/src/Umbraco.Core/PublishedContentHelper.cs index 1e7fc1ef18..8a3242c831 100644 --- a/src/Umbraco.Core/PublishedContentHelper.cs +++ b/src/Umbraco.Core/PublishedContentHelper.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Xml.Linq; using Umbraco.Core.Configuration; using Umbraco.Core.Dynamics; +using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; @@ -43,8 +44,9 @@ namespace Umbraco.Core /// /// /// + /// /// - internal static Guid GetDataType(ApplicationContext applicationContext, string docTypeAlias, string propertyAlias) + internal static Guid GetDataType(ApplicationContext applicationContext, string docTypeAlias, string propertyAlias, PublishedItemType itemType) { if (GetDataTypeCallback != null) return GetDataTypeCallback(docTypeAlias, propertyAlias); @@ -52,7 +54,19 @@ namespace Umbraco.Core var key = new Tuple(docTypeAlias, propertyAlias); return PropertyTypeCache.GetOrAdd(key, tuple => { - var result = applicationContext.Services.ContentTypeService.GetContentType(docTypeAlias); + IContentTypeComposition result = null; + switch (itemType) + { + case PublishedItemType.Content: + result = applicationContext.Services.ContentTypeService.GetContentType(docTypeAlias); + break; + case PublishedItemType.Media: + applicationContext.Services.ContentTypeService.GetMediaType(docTypeAlias); + break; + default: + throw new ArgumentOutOfRangeException("itemType"); + } + if (result == null) return Guid.Empty; //SD: we need to check for 'any' here because the collection is backed by KeyValuePair which is a struct diff --git a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs index 2086b9b5d0..efa50075bf 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Text.RegularExpressions; +using System.Web; using System.Xml.Linq; using System.Xml.XPath; using Examine; @@ -16,6 +17,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Tests.TestHelpers; +using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.UmbracoExamine; using Umbraco.Web; using Umbraco.Web.PublishedCache; @@ -68,6 +70,38 @@ namespace Umbraco.Tests.PublishedContent return GetNode(id, GetUmbracoContext("/test", 1234)); } + [Test] + public void Get_Property_Value_Uses_Converter() + { + var mType = MockedContentTypes.CreateImageMediaType(); + //lets add an RTE to this + mType.PropertyGroups.First().PropertyTypes.Add( + new PropertyType(new Guid(), DataTypeDatabaseType.Nvarchar) + { + Alias = "content", + Name = "Rich Text", + DataTypeDefinitionId = -87 //tiny mce + }); + ServiceContext.ContentTypeService.Save(mType); + var media = MockedMedia.CreateMediaImage(mType, -1); + media.Properties["content"].Value = "
This is some content
"; + ServiceContext.MediaService.Save(media); + + var publishedMedia = GetNode(media.Id); + + var propVal = publishedMedia.GetPropertyValue("content"); + Assert.IsTrue(TypeHelper.IsTypeAssignableFrom(propVal.GetType())); + Assert.AreEqual("
This is some content
", propVal.ToString()); + + var propVal2 = publishedMedia.GetPropertyValue("content"); + Assert.IsTrue(TypeHelper.IsTypeAssignableFrom(propVal2.GetType())); + Assert.AreEqual("
This is some content
", propVal2.ToString()); + + var propVal3 = publishedMedia.GetPropertyValue("Content"); + Assert.IsTrue(TypeHelper.IsTypeAssignableFrom(propVal3.GetType())); + Assert.AreEqual("
This is some content
", propVal3.ToString()); + } + [Test] public void Ensure_Children_Sorted_With_Examine() { @@ -339,7 +373,6 @@ namespace Umbraco.Tests.PublishedContent Assert.AreEqual(mChild1.Id, publishedSubChild1.Parent.Id); } - [Test] public void Ancestors_Without_Examine() { diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index a6655c55ce..b36a9d7880 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -153,7 +153,10 @@ namespace Umbraco.Web //Here we need to put the value through the IPropertyEditorValueConverter's //get the data type id for the current property - var dataType = PublishedContentHelper.GetDataType(ApplicationContext.Current, doc.DocumentTypeAlias, alias); + var dataType = PublishedContentHelper.GetDataType( + ApplicationContext.Current, doc.DocumentTypeAlias, alias, + doc.ItemType); + //convert the string value to a known type var converted = PublishedContentHelper.ConvertPropertyValue(p.Value, dataType, doc.DocumentTypeAlias, alias); return converted.Success