@@ -39,23 +39,37 @@ public BlockEditorValueConnector(IContentTypeService contentTypeService, Lazy<Va
39
39
40
40
public string ToArtifact ( object value , PropertyType propertyType , ICollection < ArtifactDependency > dependencies )
41
41
{
42
+ _logger . Info < BlockEditorValueConnector > ( "Converting {PropertyType} to artifact." , propertyType . Alias ) ;
42
43
var svalue = value as string ;
43
44
44
45
// nested values will arrive here as JObject - convert to string to enable reuse of same code as when non-nested.
45
46
if ( value is JObject )
47
+ {
48
+ _logger . Debug < BlockListValueConnector > ( "Value is a JObject - converting to string." ) ;
46
49
svalue = value . ToString ( ) ;
50
+ }
47
51
48
52
if ( string . IsNullOrWhiteSpace ( svalue ) )
53
+ {
54
+ _logger . Warn < BlockEditorValueConnector > ( $ "Value is null or whitespace. Skipping conversion to artifact.") ;
49
55
return null ;
56
+ }
50
57
51
58
if ( svalue . DetectIsJson ( ) == false )
59
+ {
60
+ _logger . Warn < BlockListValueConnector > ( "Value '{Value}' is not a json string. Skipping conversion to artifact." , svalue ) ;
52
61
return null ;
62
+ }
63
+
53
64
var blockEditorValue = JsonConvert . DeserializeObject < BlockEditorValue > ( svalue ) ;
54
65
55
66
if ( blockEditorValue == null )
67
+ {
68
+ _logger . Warn < BlockEditorValueConnector > ( "Deserialized value is null. Skipping conversion to artifact." ) ;
56
69
return null ;
70
+ }
57
71
58
- var allBlocks = blockEditorValue . Content . Concat ( blockEditorValue . Settings ) ;
72
+ var allBlocks = blockEditorValue . Content . Concat ( blockEditorValue . Settings ) . ToList ( ) ;
59
73
60
74
// get all the content types used in block editor items
61
75
var allContentTypes = allBlocks . Select ( x => x . ContentTypeKey )
@@ -76,6 +90,7 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
76
90
//Ensure that these content types have dependencies added
77
91
foreach ( var contentType in allContentTypes . Values )
78
92
{
93
+ _logger . Debug < BlockEditorValueConnector > ( "Adding dependency for content type {ContentType}." , contentType . Alias ) ;
79
94
dependencies . Add ( new ArtifactDependency ( contentType . GetUdi ( ) , false , ArtifactDependencyMode . Match ) ) ;
80
95
}
81
96
@@ -85,23 +100,23 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
85
100
86
101
foreach ( var key in block . PropertyValues . Keys . ToArray ( ) )
87
102
{
88
- var propType = contentType . CompositionPropertyTypes . FirstOrDefault ( x => x . Alias == key ) ;
103
+ var innerPropertyType = contentType . CompositionPropertyTypes . FirstOrDefault ( x => x . Alias == key ) ;
89
104
90
- if ( propType == null )
105
+ if ( innerPropertyType == null )
91
106
{
92
- _logger . Debug < BlockEditorValueConnector > ( "No property type found with alias {Key } on content type {ContentTypeAlias}." , key , contentType . Alias ) ;
107
+ _logger . Warn < BlockEditorValueConnector > ( "No property type found with alias {PropertyTypeAlias } on content type {ContentTypeAlias}." , key , contentType . Alias ) ;
93
108
continue ;
94
109
}
95
110
96
111
// fetch the right value connector from the collection of connectors, intended for use with this property type.
97
112
// throws if not found - no need for a null check
98
- var propValueConnector = ValueConnectors . Get ( propType ) ;
113
+ var propertyValueConnector = ValueConnectors . Get ( innerPropertyType ) ;
99
114
100
115
// pass the value, property type and the dependencies collection to the connector to get a "artifact" value
101
- var val = block . PropertyValues [ key ] ;
102
- object parsedValue = propValueConnector . ToArtifact ( val , propType , dependencies ) ;
116
+ var innerValue = block . PropertyValues [ key ] ;
117
+ object parsedValue = propertyValueConnector . ToArtifact ( innerValue , innerPropertyType , dependencies ) ;
103
118
104
- _logger . Debug < BlockEditorValueConnector > ( "Map {Key} value '{PropertyValue}' to '{ParsedValue}' using {PropValueConnectorType } for {PropTypeAlias }." , key , block . PropertyValues [ key ] , parsedValue , propValueConnector . GetType ( ) , propType . Alias ) ;
119
+ _logger . Debug < BlockEditorValueConnector > ( "Mapped {Key} value '{PropertyValue}' to '{ParsedValue}' using {PropertyValueConnectorType } for {PropertyTypeAlias }." , key , block . PropertyValues [ key ] , parsedValue , propertyValueConnector . GetType ( ) , innerPropertyType . Alias ) ;
105
120
106
121
parsedValue = parsedValue ? . ToString ( ) ;
107
122
@@ -110,7 +125,8 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
110
125
}
111
126
112
127
value = JsonConvert . SerializeObject ( blockEditorValue ) ;
113
- return ( string ) value ;
128
+ _logger . Info < BlockEditorValueConnector > ( "Finished converting {PropertyType} to artifact." , propertyType . Alias ) ;
129
+ return ( string ) value ;
114
130
}
115
131
116
132
public object FromArtifact ( string value , PropertyType propertyType , object currentValue )
@@ -155,7 +171,7 @@ public object FromArtifact(string value, PropertyType propertyType, object curre
155
171
156
172
if ( innerPropertyType == null )
157
173
{
158
- _logger . Debug < BlockEditorValueConnector > ( "No property type found with alias {Key} on content type {ContentTypeAlias}." , key , contentType . Alias ) ;
174
+ _logger . Warn < BlockEditorValueConnector > ( "No property type found with alias {Key} on content type {ContentTypeAlias}." , key , contentType . Alias ) ;
159
175
continue ;
160
176
}
161
177
0 commit comments