1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Linq ;
3
4
using Newtonsoft . Json ;
4
5
using Newtonsoft . Json . Linq ;
5
6
using Our . Umbraco . DocTypeGridEditor . Models ;
@@ -31,15 +32,16 @@ public static IPublishedContent ConvertValueToContent(string id, string docTypeA
31
32
if ( Guid . TryParse ( docTypeAlias , out docTypeGuid ) )
32
33
docTypeAlias = Services . ContentTypeService . GetAliasByGuid ( docTypeGuid ) ;
33
34
34
- var contentType = PublishedContentType . Get ( PublishedItemType . Content , docTypeAlias ) ;
35
- var properties = new List < IPublishedProperty > ( ) ;
35
+ var publishedContentType = PublishedContentType . Get ( PublishedItemType . Content , docTypeAlias ) ;
36
+ var contentType = ApplicationContext . Current . Services . ContentTypeService . GetContentType ( docTypeAlias ) ;
37
+ var properties = new List < IPublishedProperty > ( ) ;
36
38
37
39
// Convert all the properties
38
40
var data = JsonConvert . DeserializeObject ( dataJson ) ;
39
41
var propValues = ( ( JObject ) data ) . ToObject < Dictionary < string , object > > ( ) ;
40
42
foreach ( var jProp in propValues )
41
43
{
42
- var propType = contentType . GetPropertyType ( jProp . Key ) ;
44
+ var propType = publishedContentType . GetPropertyType ( jProp . Key ) ;
43
45
if ( propType != null )
44
46
{
45
47
/* Because we never store the value in the database, we never run the property editors
@@ -58,7 +60,14 @@ public static IPublishedContent ConvertValueToContent(string id, string docTypeA
58
60
59
61
var newValue = propEditor . ValueEditor . ConvertEditorToDb ( contentPropData , jProp . Value ) ;
60
62
61
- properties . Add ( new DetachedPublishedProperty ( propType , newValue ) ) ;
63
+ /* Now that we have the DB stored value, we actually need to then convert it into it's
64
+ * XML serialized state as expected by the published property by calling ConvertDbToString
65
+ */
66
+ var propType2 = contentType . PropertyTypes . Single ( x => x . Alias == propType . PropertyTypeAlias ) ;
67
+ var newValue2 = propEditor . ValueEditor . ConvertDbToString ( new Property ( propType2 , newValue ) , propType2 ,
68
+ ApplicationContext . Current . Services . DataTypeService ) ;
69
+
70
+ properties . Add ( new DetachedPublishedProperty ( propType , newValue2 ) ) ;
62
71
}
63
72
}
64
73
@@ -69,7 +78,7 @@ public static IPublishedContent ConvertValueToContent(string id, string docTypeA
69
78
// Do nothing, we just want to parse out the name if we can
70
79
}
71
80
72
- return new DetachedPublishedContent ( nameObj == null ? null : nameObj . ToString ( ) , contentType ,
81
+ return new DetachedPublishedContent ( nameObj == null ? null : nameObj . ToString ( ) , publishedContentType ,
73
82
properties . ToArray ( ) ) ;
74
83
}
75
84
} ) ;
0 commit comments