Skip to content

Commit 1c36af8

Browse files
author
Paul Johnson
authored
Map both settings and content data via property editors. (#11722)
For persistence and rendering property editor frontend components.
1 parent 13a51d3 commit 1c36af8

File tree

1 file changed

+61
-48
lines changed

1 file changed

+61
-48
lines changed

src/Umbraco.Web/PropertyEditors/BlockEditorPropertyEditor.cs

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -123,52 +123,58 @@ public override object ToEditor(Property property, IDataTypeService dataTypeServ
123123
if (blockEditorData == null)
124124
return string.Empty;
125125

126-
foreach (var row in blockEditorData.BlockValue.ContentData)
126+
void MapBlockItemData(List<BlockItemData> items)
127127
{
128-
foreach (var prop in row.PropertyValues)
128+
foreach (var row in items)
129129
{
130-
// create a temp property with the value
131-
// - force it to be culture invariant as the block editor can't handle culture variant element properties
132-
prop.Value.PropertyType.Variations = ContentVariation.Nothing;
133-
var tempProp = new Property(prop.Value.PropertyType);
134-
tempProp.SetValue(prop.Value.Value);
135-
136-
var propEditor = _propertyEditors[prop.Value.PropertyType.PropertyEditorAlias];
137-
if (propEditor == null)
130+
foreach (var prop in row.PropertyValues)
138131
{
139-
// NOTE: This logic was borrowed from Nested Content and I'm unsure why it exists.
140-
// if the property editor doesn't exist I think everything will break anyways?
141-
// update the raw value since this is what will get serialized out
142-
row.RawPropertyValues[prop.Key] = tempProp.GetValue()?.ToString();
143-
continue;
144-
}
132+
// create a temp property with the value
133+
// - force it to be culture invariant as the block editor can't handle culture variant element properties
134+
prop.Value.PropertyType.Variations = ContentVariation.Nothing;
135+
var tempProp = new Property(prop.Value.PropertyType);
136+
tempProp.SetValue(prop.Value.Value);
137+
138+
var propEditor = _propertyEditors[prop.Value.PropertyType.PropertyEditorAlias];
139+
if (propEditor == null)
140+
{
141+
// NOTE: This logic was borrowed from Nested Content and I'm unsure why it exists.
142+
// if the property editor doesn't exist I think everything will break anyways?
143+
// update the raw value since this is what will get serialized out
144+
row.RawPropertyValues[prop.Key] = tempProp.GetValue()?.ToString();
145+
continue;
146+
}
145147

146-
var dataType = dataTypeService.GetDataType(prop.Value.PropertyType.DataTypeId);
147-
if (dataType == null)
148-
{
149-
// deal with weird situations by ignoring them (no comment)
150-
row.PropertyValues.Remove(prop.Key);
151-
_logger.Warn<BlockEditorPropertyValueEditor,string,Guid,string>(
152-
"ToEditor removed property value {PropertyKey} in row {RowId} for property type {PropertyTypeAlias}",
153-
prop.Key, row.Key, property.PropertyType.Alias);
154-
continue;
155-
}
148+
var dataType = dataTypeService.GetDataType(prop.Value.PropertyType.DataTypeId);
149+
if (dataType == null)
150+
{
151+
// deal with weird situations by ignoring them (no comment)
152+
row.PropertyValues.Remove(prop.Key);
153+
_logger.Warn<BlockEditorPropertyValueEditor, string, Guid, string>(
154+
"ToEditor removed property value {PropertyKey} in row {RowId} for property type {PropertyTypeAlias}",
155+
prop.Key, row.Key, property.PropertyType.Alias);
156+
continue;
157+
}
156158

157-
if (!valEditors.TryGetValue(dataType.Id, out var valEditor))
158-
{
159-
var tempConfig = dataType.Configuration;
160-
valEditor = propEditor.GetValueEditor(tempConfig);
159+
if (!valEditors.TryGetValue(dataType.Id, out var valEditor))
160+
{
161+
var tempConfig = dataType.Configuration;
162+
valEditor = propEditor.GetValueEditor(tempConfig);
161163

162-
valEditors.Add(dataType.Id, valEditor);
163-
}
164+
valEditors.Add(dataType.Id, valEditor);
165+
}
164166

165-
var convValue = valEditor.ToEditor(tempProp, dataTypeService);
167+
var convValue = valEditor.ToEditor(tempProp, dataTypeService);
166168

167-
// update the raw value since this is what will get serialized out
168-
row.RawPropertyValues[prop.Key] = convValue;
169+
// update the raw value since this is what will get serialized out
170+
row.RawPropertyValues[prop.Key] = convValue;
171+
}
169172
}
170173
}
171174

175+
MapBlockItemData(blockEditorData.BlockValue.ContentData);
176+
MapBlockItemData(blockEditorData.BlockValue.SettingsData);
177+
172178
// return json convertable object
173179
return blockEditorData.BlockValue;
174180
}
@@ -198,28 +204,35 @@ public override object FromEditor(ContentPropertyData editorValue, object curren
198204
if (blockEditorData == null || blockEditorData.BlockValue.ContentData.Count == 0)
199205
return string.Empty;
200206

201-
foreach (var row in blockEditorData.BlockValue.ContentData)
207+
void MapBlockItemData(List<BlockItemData> items)
202208
{
203-
foreach (var prop in row.PropertyValues)
209+
foreach (var row in items)
204210
{
205-
// Fetch the property types prevalue
206-
var propConfiguration = _dataTypeService.GetDataType(prop.Value.PropertyType.DataTypeId).Configuration;
211+
foreach (var prop in row.PropertyValues)
212+
{
213+
// Fetch the property types prevalue
214+
var propConfiguration = _dataTypeService.GetDataType(prop.Value.PropertyType.DataTypeId)
215+
.Configuration;
207216

208-
// Lookup the property editor
209-
var propEditor = _propertyEditors[prop.Value.PropertyType.PropertyEditorAlias];
210-
if (propEditor == null) continue;
217+
// Lookup the property editor
218+
var propEditor = _propertyEditors[prop.Value.PropertyType.PropertyEditorAlias];
219+
if (propEditor == null) continue;
211220

212-
// Create a fake content property data object
213-
var contentPropData = new ContentPropertyData(prop.Value.Value, propConfiguration);
221+
// Create a fake content property data object
222+
var contentPropData = new ContentPropertyData(prop.Value.Value, propConfiguration);
214223

215-
// Get the property editor to do it's conversion
216-
var newValue = propEditor.GetValueEditor().FromEditor(contentPropData, prop.Value.Value);
224+
// Get the property editor to do it's conversion
225+
var newValue = propEditor.GetValueEditor().FromEditor(contentPropData, prop.Value.Value);
217226

218-
// update the raw value since this is what will get serialized out
219-
row.RawPropertyValues[prop.Key] = newValue;
227+
// update the raw value since this is what will get serialized out
228+
row.RawPropertyValues[prop.Key] = newValue;
229+
}
220230
}
221231
}
222232

233+
MapBlockItemData(blockEditorData.BlockValue.ContentData);
234+
MapBlockItemData(blockEditorData.BlockValue.SettingsData);
235+
223236
// return json
224237
return JsonConvert.SerializeObject(blockEditorData.BlockValue);
225238
}

0 commit comments

Comments
 (0)