@@ -66,7 +66,7 @@ public string GetValue(GridValue.GridControl gridControl, ICollection<ArtifactDe
66
66
_logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "GetValue - PropertyTypeAlias - { propertyType . Alias } ") ;
67
67
68
68
// test if there's a value for the given property
69
- if ( IsValueNull ( docTypeGridEditorContent , propertyType , out var value ) )
69
+ if ( ! TryGetValue ( docTypeGridEditorContent , propertyType , out var value ) )
70
70
{
71
71
continue ;
72
72
}
@@ -77,46 +77,21 @@ public string GetValue(GridValue.GridControl gridControl, ICollection<ArtifactDe
77
77
continue ;
78
78
}
79
79
80
- JToken jtokenValue = null ;
81
- var parsedValue = string . Empty ;
82
-
83
80
// throws if not found - no need for a null check
84
81
var propValueConnector = ValueConnectors . Get ( propertyType ) ;
85
82
86
- _logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "GetValue - PropertyValueConnectorAlias - { propValueConnector . PropertyEditorAliases } ") ;
83
+ _logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "GetValue - PropertyValueConnectorAlias - { string . Join ( ", " , propValueConnector . PropertyEditorAliases ) } ") ;
87
84
_logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "GetValue - propertyTypeValue - { value } ") ;
88
85
89
- //properties like MUP / Nested Content seems to be in json and it breaks, so pass it back as jtokenValue right away
90
- if ( IsJson ( value ) )
91
- {
92
- jtokenValue = GetJTokenValue ( value ) ;
93
- _logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "GetValue - Inner JtokenValue - Eg MUP/NestedContent { jtokenValue } ") ;
94
- }
95
- else
96
- {
97
- parsedValue = propValueConnector . ToArtifact ( value , propertyType , dependencies ) ;
98
-
99
- _logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "GetValue - ParsedValue - { parsedValue } ") ;
86
+ //properties like MUP / Nested Content are JSON, we need to convert to string for the conversion to artifact
87
+ string parsedValue = propValueConnector . ToArtifact ( IsJson ( value ) ? value . ToString ( ) : value , propertyType , dependencies ) ;
100
88
101
- if ( IsJson ( parsedValue ) )
102
- {
103
- // if that's the case we'll need to add it as a json object instead of string to avoid it being escaped
104
- jtokenValue = GetJTokenValue ( parsedValue ) ;
105
- }
106
- }
89
+ _logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "GetValue - ParsedValue - { parsedValue } ") ;
107
90
108
- if ( jtokenValue != null )
109
- {
110
- _logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "GetValue - JtokenValue - { jtokenValue } ") ;
111
- docTypeGridEditorContent . Value [ propertyType . Alias ] = jtokenValue ;
112
- }
113
- else
114
- {
115
- docTypeGridEditorContent . Value [ propertyType . Alias ] = parsedValue ;
116
- }
91
+ docTypeGridEditorContent . Value [ propertyType . Alias ] = parsedValue ;
117
92
}
118
93
119
- var resolvedValue = JsonConvert . SerializeObject ( docTypeGridEditorContent ) ;
94
+ var resolvedValue = JsonConvert . SerializeObject ( docTypeGridEditorContent , Formatting . None ) ;
120
95
121
96
_logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "GetValue - ResolvedValue - { resolvedValue } ") ;
122
97
@@ -160,8 +135,6 @@ public void SetValue(GridValue.GridControl gridControl)
160
135
161
136
foreach ( var propertyType in propertyTypes )
162
137
{
163
- JToken jtokenValue = null ;
164
-
165
138
_logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "SetValue - PropertyEditorAlias -- { propertyType . PropertyEditorAlias } ") ;
166
139
167
140
if ( ! docTypeGridEditorContent . Value . TryGetValue ( propertyType . Alias , out object value ) || value == null )
@@ -172,59 +145,25 @@ public void SetValue(GridValue.GridControl gridControl)
172
145
173
146
// throws if not found - no need for a null check
174
147
var propValueConnector = ValueConnectors . Get ( propertyType ) ;
175
- propValueConnector . FromArtifact ( value . ToString ( ) , propertyType , "" ) ;
176
-
177
- _logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "SetValue - PropertyValueConnecterType - { propValueConnector . GetType ( ) } ") ;
178
- _logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "SetValue - Value - { value } ") ;
148
+ var convertedValue = propValueConnector . FromArtifact ( value . ToString ( ) , propertyType , string . Empty ) ;
179
149
180
- // test if there's a value for the given property
181
- object convertedValue ;
182
- //don't convert if it's json (MUP/Nested) / udi (Content/Media/Multi Pickers) / guid (form picker) / rte / textstring values
183
- if ( IsJson ( value ) || IsUdi ( value ) || IsGuid ( value ) || IsText ( propertyType . PropertyEditorAlias ) )
184
- {
185
- _logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "SetValue - IsJsonValue / IsUdiValue / IsGuidValue / IsTextValue - { value } ") ;
186
- convertedValue = CleanValue ( propertyType . PropertyEditorAlias , value ) ;
187
- }
188
- else
150
+ JToken jtokenValue = null ;
151
+ if ( IsJson ( convertedValue ) )
189
152
{
190
- //using mockContent to get the converted values
191
- var mockProperty = new Property ( propertyType ) ;
192
- var mockContent = new Content ( "mockContentGrid" , - 1 , new ContentType ( - 1 ) , new PropertyCollection ( new List < Property > { mockProperty } ) ) ;
193
- convertedValue = mockContent . GetValue ( mockProperty . Alias ) ;
194
- _logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "SetValue - ConvertedValue - Before - { convertedValue } ") ;
153
+ // test if the value is a json object (thus could be a nested complex editor)
154
+ // if that's the case we'll need to add it as a json object instead of string to avoid it being escaped
155
+ jtokenValue = GetJTokenValue ( convertedValue ) ;
195
156
}
196
157
197
- // integers needs to be converted into strings for DTGE to work
198
- if ( convertedValue is int )
199
- {
200
- docTypeGridEditorContent . Value [ propertyType . Alias ] = convertedValue . ToString ( ) ;
201
- }
202
- else if ( convertedValue == null )
158
+ if ( jtokenValue != null )
203
159
{
204
- //Assign the null back - otherwise the check for JSON will fail as we cant convert a null to a string
205
- //NOTE: LinkPicker2 for example if no link set is returning a null as opposed to empty string
206
- docTypeGridEditorContent . Value [ propertyType . Alias ] = null ;
160
+ _logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "SetValue - jtokenValue - { jtokenValue } ") ;
161
+ docTypeGridEditorContent . Value [ propertyType . Alias ] = jtokenValue ;
207
162
}
208
163
else
209
164
{
210
- _logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "SetValue - ConvertedValue - After - { convertedValue } ") ;
211
-
212
- if ( IsJson ( convertedValue ) )
213
- {
214
- // test if the value is a json object (thus could be a nested complex editor)
215
- // if that's the case we'll need to add it as a json object instead of string to avoid it being escaped
216
- jtokenValue = GetJTokenValue ( convertedValue ) ;
217
- }
218
-
219
- if ( jtokenValue != null )
220
- {
221
- _logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "SetValue - jtokenValue - { jtokenValue } ") ;
222
- docTypeGridEditorContent . Value [ propertyType . Alias ] = jtokenValue ;
223
- }
224
- else
225
- {
226
- docTypeGridEditorContent . Value [ propertyType . Alias ] = convertedValue ;
227
- }
165
+ _logger . Debug < DocTypeGridEditorCellValueConnector > ( $ "SetValue - convertedValue - { convertedValue } ") ;
166
+ docTypeGridEditorContent . Value [ propertyType . Alias ] = convertedValue ;
228
167
}
229
168
}
230
169
@@ -237,24 +176,6 @@ public void SetValue(GridValue.GridControl gridControl)
237
176
238
177
private bool IsJson ( object value ) => value != null && value . ToString ( ) . DetectIsJson ( ) ;
239
178
240
- private bool IsGuid ( object value ) => Guid . TryParse ( value . ToString ( ) , out _ ) ;
241
-
242
- private bool IsUdi ( object value ) =>
243
- //for picker like content/media either single or multi, it comes with udi values
244
- value . ToString ( ) . Contains ( "umb://" ) ;
245
-
246
- private bool IsText ( string editorAlias ) =>
247
- //if it's either RTE / Textstring data type
248
- IsRichtext ( editorAlias ) || IsTextstring ( editorAlias ) ;
249
-
250
- private bool IsRichtext ( string editorAlias ) => editorAlias . InvariantEquals ( "Umbraco.TinyMCE" ) ;
251
-
252
- private bool IsTextstring ( string editorAlias ) => editorAlias . InvariantEquals ( "Umbraco.TextBox" ) ;
253
-
254
- private string CleanValue ( string editorAlias , object value ) =>
255
- //can't tell why textstring have got a weird character 's' in front coming from deploy? so removing first char if that's the case
256
- IsTextstring ( editorAlias ) ? value . ToString ( ) . Substring ( 1 ) : value . ToString ( ) ;
257
-
258
179
private bool AddUdiDependency ( ICollection < ArtifactDependency > dependencies , object value )
259
180
{
260
181
if ( Udi . TryParse ( value . ToString ( ) , out var udi ) )
@@ -267,15 +188,15 @@ private bool AddUdiDependency(ICollection<ArtifactDependency> dependencies, obje
267
188
return false ;
268
189
}
269
190
270
- private bool IsValueNull ( DocTypeGridEditorValue docTypeGridEditorContent , PropertyType propertyType , out object objVal )
191
+ private bool TryGetValue ( DocTypeGridEditorValue docTypeGridEditorContent , PropertyType propertyType , out object objVal )
271
192
{
272
193
if ( ! docTypeGridEditorContent . Value . TryGetValue ( propertyType . Alias , out objVal ) || objVal == null )
273
194
{
274
195
_logger . Debug < DocTypeGridEditorCellValueConnector > ( "GetValue - Value is null" ) ;
275
- return true ;
196
+ return false ;
276
197
}
277
198
278
- return false ;
199
+ return true ;
279
200
}
280
201
281
202
private class DocTypeGridEditorValue
0 commit comments