@@ -32,7 +32,7 @@ public static IPublishedContent ConvertValueToContent(string id, string contentT
32
32
return ConvertValue ( id , contentTypeAlias , dataJson ) ;
33
33
34
34
return ( IPublishedContent ) ApplicationContext . Current . ApplicationCache . RequestCache . GetCacheItem (
35
- string . Concat ( "DocTypeGridEditorHelper.ConvertValueToContent_" , id , "_" , contentTypeAlias ) ,
35
+ string . Concat ( "Our.Umbraco.DocTypeGridEditor.Helpers. DocTypeGridEditorHelper.ConvertValueToContent_" , id , "_" , contentTypeAlias ) ,
36
36
( ) =>
37
37
{
38
38
return ConvertValue ( id , contentTypeAlias , dataJson ) ;
@@ -41,22 +41,17 @@ public static IPublishedContent ConvertValueToContent(string id, string contentT
41
41
42
42
private static IPublishedContent ConvertValue ( string id , string contentTypeAlias , string dataJson )
43
43
{
44
- using ( var timer = DisposableTimer . DebugDuration < DocTypeGridEditorHelper > ( string . Format ( "ConvertValueToContent ({0}, {1})" , id , contentTypeAlias ) ) )
44
+ using ( var timer = DisposableTimer . DebugDuration < DocTypeGridEditorHelper > ( string . Format ( "ConvertValue ({0}, {1})" , id , contentTypeAlias ) ) )
45
45
{
46
- Guid contentTypeGuid ;
47
- if ( Guid . TryParse ( contentTypeAlias , out contentTypeGuid ) )
48
- contentTypeAlias = Services . ContentTypeService . GetAliasByGuid ( contentTypeGuid ) ;
49
-
50
- var publishedContentType = PublishedContentType . Get ( PublishedItemType . Content , contentTypeAlias ) ;
51
- var contentType = Services . ContentTypeService . GetContentType ( contentTypeAlias ) ;
46
+ var contentTypes = GetContentTypesByAlias ( contentTypeAlias ) ;
52
47
var properties = new List < IPublishedProperty > ( ) ;
53
48
54
49
// Convert all the properties
55
50
var data = JsonConvert . DeserializeObject ( dataJson ) ;
56
51
var propValues = ( ( JObject ) data ) . ToObject < Dictionary < string , object > > ( ) ;
57
52
foreach ( var jProp in propValues )
58
53
{
59
- var propType = publishedContentType . GetPropertyType ( jProp . Key ) ;
54
+ var propType = contentTypes . PublishedContentType . GetPropertyType ( jProp . Key ) ;
60
55
if ( propType != null )
61
56
{
62
57
/* Because we never store the value in the database, we never run the property editors
@@ -65,8 +60,7 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
65
60
* we go on to convert the value for the view.
66
61
*/
67
62
var propEditor = PropertyEditorResolver . Current . GetByAlias ( propType . PropertyEditorAlias ) ;
68
- var propPreValues = Services . DataTypeService . GetPreValuesCollectionByDataTypeId (
69
- propType . DataTypeId ) ;
63
+ var propPreValues = GetPreValuesCollectionByDataTypeId ( propType . DataTypeId ) ;
70
64
71
65
var contentPropData = new ContentPropertyData (
72
66
jProp . Value ,
@@ -78,7 +72,7 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
78
72
/* Now that we have the DB stored value, we actually need to then convert it into it's
79
73
* XML serialized state as expected by the published property by calling ConvertDbToString
80
74
*/
81
- var propType2 = contentType . CompositionPropertyTypes . Single ( x => x . Alias . InvariantEquals ( propType . PropertyTypeAlias ) ) ;
75
+ var propType2 = contentTypes . ContentType . CompositionPropertyTypes . Single ( x => x . Alias . InvariantEquals ( propType . PropertyTypeAlias ) ) ;
82
76
83
77
Property prop2 = null ;
84
78
try
@@ -117,11 +111,43 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
117
111
var containerNode = pcr != null && pcr . HasPublishedContent ? pcr . PublishedContent : null ;
118
112
119
113
return new DetachedPublishedContent ( nameObj != null ? nameObj . ToString ( ) : null ,
120
- publishedContentType ,
114
+ contentTypes . PublishedContentType ,
121
115
properties . ToArray ( ) ,
122
116
containerNode ) ;
123
117
}
124
118
125
119
}
120
+
121
+ private static PreValueCollection GetPreValuesCollectionByDataTypeId ( int dataTypeId )
122
+ {
123
+ return ( PreValueCollection ) ApplicationContext . Current . ApplicationCache . RuntimeCache . GetCacheItem ( "Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetPreValuesCollectionByDataTypeId_" + dataTypeId ,
124
+ ( ) => Services . DataTypeService . GetPreValuesCollectionByDataTypeId ( dataTypeId ) ) ;
125
+ }
126
+
127
+ private static ContentTypeContainer GetContentTypesByAlias ( string contentTypeAlias )
128
+ {
129
+ Guid contentTypeGuid ;
130
+ if ( Guid . TryParse ( contentTypeAlias , out contentTypeGuid ) )
131
+ contentTypeAlias = GetContentTypeAliasByGuid ( contentTypeGuid ) ;
132
+
133
+ return ( ContentTypeContainer ) ApplicationContext . Current . ApplicationCache . RuntimeCache . GetCacheItem ( "Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetContentTypesByAlias_" + contentTypeAlias ,
134
+ ( ) => new ContentTypeContainer
135
+ {
136
+ PublishedContentType = PublishedContentType . Get ( PublishedItemType . Content , contentTypeAlias ) ,
137
+ ContentType = Services . ContentTypeService . GetContentType ( contentTypeAlias )
138
+ } ) ;
139
+ }
140
+
141
+ private static string GetContentTypeAliasByGuid ( Guid contentTypeGuid )
142
+ {
143
+ return ( string ) ApplicationContext . Current . ApplicationCache . RuntimeCache . GetCacheItem ( "Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetContentTypeAliasByGuid_" + contentTypeGuid ,
144
+ ( ) => Services . ContentTypeService . GetAliasByGuid ( contentTypeGuid ) ) ;
145
+ }
146
+ }
147
+
148
+ public class ContentTypeContainer
149
+ {
150
+ public PublishedContentType PublishedContentType { get ; set ; }
151
+ public IContentType ContentType { get ; set ; }
126
152
}
127
153
}
0 commit comments