@@ -39,78 +39,85 @@ public static IPublishedElement ConvertValueToContent(string id, string contentT
39
39
40
40
private static IPublishedElement ConvertValue ( string id , string contentTypeAlias , string dataJson )
41
41
{
42
- var contentTypes = GetContentTypesByAlias ( contentTypeAlias ) ;
43
- var properties = new List < IPublishedProperty > ( ) ;
42
+ var contentTypes = GetContentTypesByAlias ( contentTypeAlias ) ;
43
+ var properties = new List < IPublishedProperty > ( ) ;
44
44
45
- // Convert all the properties
46
- var data = JsonConvert . DeserializeObject ( dataJson ) ;
47
- var propValues = ( ( JObject ) data ) . ToObject < Dictionary < string , object > > ( ) ;
48
- foreach ( var jProp in propValues )
49
- {
50
- var propType = contentTypes . PublishedContentType . GetPropertyType ( jProp . Key ) ;
51
- if ( propType == null )
52
- continue ;
45
+ // Convert all the properties
46
+ var data = JsonConvert . DeserializeObject ( dataJson ) ;
47
+ var propValues = ( ( JObject ) data ) . ToObject < Dictionary < string , object > > ( ) ;
48
+ foreach ( var jProp in propValues )
49
+ {
50
+ var propType = contentTypes . PublishedContentType . GetPropertyType ( jProp . Key ) ;
51
+ if ( propType == null )
52
+ continue ;
53
53
54
54
55
- /* Because we never store the value in the database, we never run the property editors
56
- * "ConvertEditorToDb" method however the property editors will expect their value to
57
- * be in a "DB" state so to get round this, we run the "ConvertEditorToDb" here before
58
- * we go on to convert the value for the view.
59
- */
60
- Current . PropertyEditors . TryGet ( propType . EditorAlias , out var propEditor ) ;
61
- var propPreValues = GetPreValuesCollectionByDataTypeId ( propType . DataType . Id ) ;
55
+ /* Because we never store the value in the database, we never run the property editors
56
+ * "ConvertEditorToDb" method however the property editors will expect their value to
57
+ * be in a "DB" state so to get round this, we run the "ConvertEditorToDb" here before
58
+ * we go on to convert the value for the view.
59
+ */
60
+ Current . PropertyEditors . TryGet ( propType . EditorAlias , out var propEditor ) ;
61
+ var propPreValues = GetPreValuesCollectionByDataTypeId ( propType . DataType . Id ) ;
62
62
63
- var contentPropData = new ContentPropertyData ( jProp . Value , propPreValues ) ;
63
+ var contentPropData = new ContentPropertyData ( jProp . Value , propPreValues ) ;
64
64
65
- var newValue = propEditor . GetValueEditor ( ) . FromEditor ( contentPropData , jProp . Value ) ;
65
+ var newValue = propEditor . GetValueEditor ( ) . FromEditor ( contentPropData , jProp . Value ) ;
66
66
67
- /* Now that we have the DB stored value, we actually need to then convert it into its
68
- * XML serialized state as expected by the published property by calling ConvertDbToString
69
- */
70
- var propType2 = contentTypes . ContentType . CompositionPropertyTypes . First ( x => x . PropertyEditorAlias . InvariantEquals ( propType . DataType . EditorAlias ) ) ;
71
-
72
- // TODO: Do we still need this weird tag conversion?
73
- //Property prop2 = null;
74
- //try
75
- //{
76
- // /* HACK: [LK:2016-04-01] When using the "Umbraco.Tags" property-editor, the converted DB value does
77
- // * not match the datatypes underlying db-column type. So it throws a "Type validation failed" exception.
78
- // * We feel that the Umbraco core isn't handling the Tags value correctly, as it should be the responsiblity
79
- // * of the "Umbraco.Tags" property-editor to handle the value conversion into the correct type.
80
- // * See: http://issues.umbraco.org/issue/U4-8279
81
- // */
82
- // prop2 = new Property(propType2.Id, newValue);
83
- // }
84
- // catch (Exception ex)
85
- // {
86
- // Current.Logger.Error<DocTypeGridEditorHelper>( "[DocTypeGridEditor] Error creating Property object.", ex );
87
- // }
88
-
89
- // if (prop2 != null)
90
- // {
67
+ /* Now that we have the DB stored value, we actually need to then convert it into its
68
+ * XML serialized state as expected by the published property by calling ConvertDbToString
69
+ */
70
+ var propType2 = contentTypes . ContentType . CompositionPropertyTypes . First ( x => x . PropertyEditorAlias . InvariantEquals ( propType . DataType . EditorAlias ) ) ;
71
+
72
+ Property prop2 = null ;
73
+ try
74
+ {
75
+ /* HACK: [LK:2016-04-01] When using the "Umbraco.Tags" property-editor, the converted DB value does
76
+ * not match the datatypes underlying db-column type. So it throws a "Type validation failed" exception.
77
+ * We feel that the Umbraco core isn't handling the Tags value correctly, as it should be the responsiblity
78
+ * of the " Umbraco.Tags" property-editor to handle the value conversion into the correct type.
79
+ * See: http://issues.umbraco.org/issue/U4-8279
80
+ */
81
+ prop2 = new Property ( propType2 ) ;
82
+ prop2 . SetValue ( newValue ) ;
83
+ }
84
+ catch ( Exception ex )
85
+ {
86
+ Current . Logger . Error ( typeof ( DocTypeGridEditorHelper ) , ex , "[DocTypeGridEditor] Error creating Property object." ) ;
87
+ }
88
+
89
+ if ( prop2 != null )
90
+ {
91
91
var newValue2 = propEditor . GetValueEditor ( ) . ConvertDbToString ( propType2 , newValue , Current . Services . DataTypeService ) ;
92
92
93
93
properties . Add ( new DetachedPublishedProperty ( propType , newValue2 ) ) ;
94
- //}
95
94
}
95
+ }
96
+
97
+ // Manually parse out the special properties
98
+ propValues . TryGetValue ( "name" , out object nameObj ) ;
99
+ Guid . TryParse ( id , out Guid key ) ;
96
100
97
- // Manually parse out the special properties
98
- propValues . TryGetValue ( "name" , out object nameObj ) ;
99
- Guid . TryParse ( id , out Guid key ) ;
101
+ // Get the current request node we are embedded in
100
102
101
- // Get the current request node we are embedded in
103
+ var pcr = Current . UmbracoContext . PublishedRequest ;
104
+ var containerNode = pcr != null && pcr . HasPublishedContent ? pcr . PublishedContent : null ;
102
105
103
- var pcr = Current . UmbracoContext . PublishedRequest ;
104
- var containerNode = pcr != null && pcr . HasPublishedContent ? pcr . PublishedContent : null ;
106
+ // Create the model based on our implementation of IPublishedElement
107
+ IPublishedElement content = new DetachedPublishedElement (
108
+ key ,
109
+ contentTypes . PublishedContentType ,
110
+ properties . ToArray ( ) ) ;
105
111
106
- // Create the model based on our implementation of IPublishedContent
107
- // TODO: FIXME!
108
- var content = new DetachedPublishedElement (
109
- key ,
110
- contentTypes . PublishedContentType ,
111
- properties . ToArray ( ) ) ;
112
+ var publishedModelFactory = Current . Factory . GetInstance < IPublishedModelFactory > ( ) ;
113
+
114
+ if ( publishedModelFactory != null )
115
+ {
116
+ // Let the current model factory create a typed model to wrap our model
117
+ content = publishedModelFactory . CreateModel ( content ) ;
118
+ }
112
119
113
- return content ;
120
+ return content ;
114
121
115
122
}
116
123
0 commit comments