Skip to content

Commit 10376a9

Browse files
author
Ronald Barendse
committed
Added recursive parsing of children
1 parent e6a1696 commit 10376a9

File tree

1 file changed

+50
-20
lines changed

1 file changed

+50
-20
lines changed

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

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
namespace Umbraco.Deploy.Contrib.Connectors.ValueConnectors
1111
{
12+
/// <summary>
13+
/// Represents a value connector for the Cogworks.Meganav property editor.
14+
/// </summary>
15+
/// <seealso cref="Umbraco.Core.Deploy.IValueConnector" />
1216
public class MeganavValueConnector : IValueConnector
1317
{
1418
/// <summary>
@@ -48,25 +52,38 @@ public string GetValue(Property property, ICollection<ArtifactDependency> depend
4852
}
4953

5054
// Parse links and convert ID to UDI
51-
var links = JArray.Parse(value);
52-
foreach (var link in links)
55+
JArray ParseLinks(JArray links)
5356
{
54-
GuidUdi guidUdi = null;
55-
int id = link.Value<int>("id");
56-
if (id != 0)
57+
foreach (var link in links)
5758
{
58-
Attempt<Guid> keyForId = this.entityService.GetKeyForId(id, UmbracoObjectTypes.Document);
59-
if (keyForId.Success)
59+
GuidUdi guidUdi = null;
60+
int id = link.Value<int>("id");
61+
if (id != 0)
6062
{
61-
guidUdi = new GuidUdi("document", keyForId.Result);
62-
dependencies.Add(new ArtifactDependency(guidUdi, false, ArtifactDependencyMode.Exist));
63+
Attempt<Guid> keyForId = this.entityService.GetKeyForId(id, UmbracoObjectTypes.Document);
64+
if (keyForId.Success)
65+
{
66+
guidUdi = new GuidUdi("document", keyForId.Result);
67+
dependencies.Add(new ArtifactDependency(guidUdi, false, ArtifactDependencyMode.Exist));
68+
}
69+
}
70+
71+
link["id"] = guidUdi?.ToString();
72+
73+
// Parse children
74+
var children = link.Value<JArray>("children");
75+
if (children != null)
76+
{
77+
link["children"] = ParseLinks(children);
6378
}
6479
}
6580

66-
link["id"] = guidUdi?.ToString();
81+
return links;
6782
}
6883

69-
return links.ToString(Formatting.None);
84+
var rootLinks = ParseLinks(JArray.Parse(value));
85+
86+
return rootLinks.ToString(Formatting.None);
7087
}
7188

7289
/// <summary>
@@ -91,23 +108,36 @@ public void SetValue(IContentBase content, string alias, string value)
91108
}
92109

93110
// Parse links and convert UDI back to local ID
94-
var links = JArray.Parse(value);
95-
foreach (var link in links)
111+
JArray ParseLinks(JArray links)
96112
{
97-
int id = 0;
98-
if (GuidUdi.TryParse(link.Value<string>("id"), out GuidUdi guidUdi))
113+
foreach (var link in links)
99114
{
100-
Attempt<int> idForUdi = this.entityService.GetIdForUdi(guidUdi);
101-
if (idForUdi.Success)
115+
int id = 0;
116+
if (GuidUdi.TryParse(link.Value<string>("id"), out GuidUdi guidUdi))
102117
{
103-
id = idForUdi.Result;
118+
Attempt<int> idForUdi = this.entityService.GetIdForUdi(guidUdi);
119+
if (idForUdi.Success)
120+
{
121+
id = idForUdi.Result;
122+
}
123+
}
124+
125+
link["id"] = id;
126+
127+
// Parse children
128+
var children = link.Value<JArray>("children");
129+
if (children != null)
130+
{
131+
link["children"] = ParseLinks(children);
104132
}
105133
}
106134

107-
link["id"] = id;
135+
return links;
108136
}
109137

110-
content.SetValue(alias, links.ToString(Formatting.None));
138+
var rootLinks = ParseLinks(JArray.Parse(value));
139+
140+
content.SetValue(alias, rootLinks.ToString(Formatting.None));
111141
}
112142
}
113143
}

0 commit comments

Comments
 (0)