Skip to content

Commit e602d83

Browse files
Merge branch 'dev-v3' into main-v3
# Conflicts: # src/Umbraco.Deploy.Contrib.Connectors/ValueConnectors/BlockEditorValueConnector.cs
2 parents 664c7a4 + 8f3978a commit e602d83

File tree

1 file changed

+46
-40
lines changed

1 file changed

+46
-40
lines changed

src/Umbraco.Deploy.Contrib.Connectors/ValueConnectors/BlockEditorValueConnector.cs

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -98,29 +98,32 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
9898
{
9999
var contentType = allContentTypes[block.ContentTypeKey];
100100

101-
foreach (var key in block.PropertyValues.Keys.ToArray())
101+
if (block.PropertyValues != null)
102102
{
103-
var innerPropertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
104-
105-
if (innerPropertyType == null)
103+
foreach (var key in block.PropertyValues.Keys.ToArray())
106104
{
107-
_logger.Warn<BlockEditorValueConnector>("No property type found with alias {PropertyType} on content type {ContentType}.", key, contentType.Alias);
108-
continue;
109-
}
105+
var innerPropertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
110106

111-
// fetch the right value connector from the collection of connectors, intended for use with this property type.
112-
// throws if not found - no need for a null check
113-
var propertyValueConnector = ValueConnectors.Get(innerPropertyType);
107+
if (innerPropertyType == null)
108+
{
109+
_logger.Warn<BlockEditorValueConnector>("No property type found with alias {PropertyType} on content type {ContentType}.", key, contentType.Alias);
110+
continue;
111+
}
114112

115-
// pass the value, property type and the dependencies collection to the connector to get a "artifact" value
116-
var innerValue = block.PropertyValues[key];
117-
object parsedValue = propertyValueConnector.ToArtifact(innerValue, innerPropertyType, dependencies);
113+
// fetch the right value connector from the collection of connectors, intended for use with this property type.
114+
// throws if not found - no need for a null check
115+
var propertyValueConnector = ValueConnectors.Get(innerPropertyType);
118116

119-
_logger.Debug<BlockEditorValueConnector>("Mapped {Key} value '{PropertyValue}' to '{ParsedValue}' using {PropertyValueConnectorType} for {PropertyType}.", key, block.PropertyValues[key], parsedValue, propertyValueConnector.GetType(), innerPropertyType.Alias);
117+
// pass the value, property type and the dependencies collection to the connector to get a "artifact" value
118+
var innerValue = block.PropertyValues[key];
119+
object parsedValue = propertyValueConnector.ToArtifact(innerValue, innerPropertyType, dependencies);
120120

121-
parsedValue = parsedValue?.ToString();
121+
_logger.Debug<BlockEditorValueConnector>("Mapped {Key} value '{PropertyValue}' to '{ParsedValue}' using {PropertyValueConnectorType} for {PropertyType}.", key, block.PropertyValues[key], parsedValue, propertyValueConnector.GetType(), innerPropertyType.Alias);
122122

123-
block.PropertyValues[key] = parsedValue;
123+
parsedValue = parsedValue?.ToString();
124+
125+
block.PropertyValues[key] = parsedValue;
126+
}
124127
}
125128
}
126129

@@ -166,41 +169,44 @@ public object FromArtifact(string value, PropertyType propertyType, object curre
166169
{
167170
var contentType = allContentTypes[block.ContentTypeKey];
168171

169-
foreach (var key in block.PropertyValues.Keys.ToArray())
172+
if (block.PropertyValues != null)
170173
{
171-
var innerPropertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
172-
173-
if (innerPropertyType == null)
174+
foreach (var key in block.PropertyValues.Keys.ToArray())
174175
{
175-
_logger.Warn<BlockEditorValueConnector>("No property type found with alias {Key} on content type {ContentType}.", key, contentType.Alias);
176-
continue;
177-
}
176+
var innerPropertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
178177

179-
// fetch the right value connector from the collection of connectors, intended for use with this property type.
180-
// throws if not found - no need for a null check
181-
var propertyValueConnector = ValueConnectors.Get(innerPropertyType);
178+
if (innerPropertyType == null)
179+
{
180+
_logger.Warn<BlockEditorValueConnector>("No property type found with alias {Key} on content type {ContentType}.", key, contentType.Alias);
181+
continue;
182+
}
182183

183-
var innerValue = block.PropertyValues[key];
184+
// fetch the right value connector from the collection of connectors, intended for use with this property type.
185+
// throws if not found - no need for a null check
186+
var propertyValueConnector = ValueConnectors.Get(innerPropertyType);
184187

185-
if (innerValue != null)
186-
{
187-
// pass the artifact value and property type to the connector to get a real value from the artifact
188-
var convertedValue = propertyValueConnector.FromArtifact(innerValue.ToString(), innerPropertyType, null);
188+
var innerValue = block.PropertyValues[key];
189189

190-
if (convertedValue == null)
190+
if (innerValue != null)
191191
{
192-
block.PropertyValues[key] = null;
192+
// pass the artifact value and property type to the connector to get a real value from the artifact
193+
var convertedValue = propertyValueConnector.FromArtifact(innerValue.ToString(), innerPropertyType, null);
194+
195+
if (convertedValue == null)
196+
{
197+
block.PropertyValues[key] = null;
198+
}
199+
else
200+
{
201+
block.PropertyValues[key] = convertedValue;
202+
}
203+
_logger.Debug<BlockEditorValueConnector>("Mapped {Key} value '{PropertyValue}' to '{ConvertedValue}' using {PropertyValueConnectorType} for {PropertyType}.", key, innerValue, convertedValue, propertyValueConnector.GetType(), innerPropertyType.Alias);
193204
}
194205
else
195206
{
196-
block.PropertyValues[key] = convertedValue;
207+
block.PropertyValues[key] = innerValue;
208+
_logger.Debug<BlockEditorValueConnector>("{Key} value was null. Setting value as null without conversion.", key);
197209
}
198-
_logger.Debug<BlockEditorValueConnector>("Mapped {Key} value '{PropertyValue}' to '{ConvertedValue}' using {PropertyValueConnectorType} for {PropertyType}.", key, innerValue, convertedValue, propertyValueConnector.GetType(), innerPropertyType.Alias);
199-
}
200-
else
201-
{
202-
block.PropertyValues[key] = innerValue;
203-
_logger.Debug<BlockEditorValueConnector>("{Key} value was null. Setting value as null without conversion.", key);
204210
}
205211
}
206212
}

0 commit comments

Comments
 (0)