Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit 50ba85a

Browse files
committed
handle null value when deserializing grid value in datavaluereference
1 parent cbd9aae commit 50ba85a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/Our.Umbraco.DocTypeGridEditor/ValueProcessing/DocTypeGridEditorDataValueReference.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public IEnumerable<UmbracoEntityReference> GetReferences(object value)
3030
var result = new List<UmbracoEntityReference>();
3131
var _propertyEditors = Current.PropertyEditors;
3232
var rawJson = value == null ? string.Empty : value is string str ? str : value.ToString();
33-
33+
3434
if(rawJson.IsNullOrWhiteSpace()) return result;
35-
35+
3636
DeserializeGridValue(rawJson, out var dtgeValues);
3737

3838
foreach (var control in dtgeValues)
@@ -67,9 +67,16 @@ internal GridValue DeserializeGridValue(string rawJson, out IEnumerable<DocTypeG
6767
{
6868
var grid = JsonConvert.DeserializeObject<GridValue>(rawJson);
6969

70-
// Find all controls that uses DTGE editor
71-
var controls = grid.Sections.SelectMany(x => x.Rows.SelectMany(r => r.Areas).SelectMany(a => a.Controls)).ToArray();
72-
dtgeValues = controls.Where(x => x.Editor.Alias.ToLowerInvariant() == "doctype").Select(x => x.Value.ToObject<DocTypeGridEditorValue>());
70+
if (grid != null)
71+
{
72+
// Find all controls that uses DTGE editor
73+
var controls = grid.Sections.SelectMany(x => x.Rows.SelectMany(r => r.Areas).SelectMany(a => a.Controls)).ToArray();
74+
dtgeValues = controls.Where(x => x.Editor.Alias.ToLowerInvariant() == "doctype").Select(x => x.Value.ToObject<DocTypeGridEditorValue>());
75+
}
76+
else
77+
{
78+
dtgeValues = Enumerable.Empty<DocTypeGridEditorValue>();
79+
}
7380

7481
return grid;
7582
}

0 commit comments

Comments
 (0)