9
9
10
10
namespace Umbraco . Deploy . Contrib . Connectors . ValueConnectors
11
11
{
12
+ /// <summary>
13
+ /// Represents a value connector for the Cogworks.Meganav property editor.
14
+ /// </summary>
15
+ /// <seealso cref="Umbraco.Core.Deploy.IValueConnector" />
12
16
public class MeganavValueConnector : IValueConnector
13
17
{
14
18
/// <summary>
@@ -48,25 +52,38 @@ public string GetValue(Property property, ICollection<ArtifactDependency> depend
48
52
}
49
53
50
54
// Parse links and convert ID to UDI
51
- var links = JArray . Parse ( value ) ;
52
- foreach ( var link in links )
55
+ JArray ParseLinks ( JArray links )
53
56
{
54
- GuidUdi guidUdi = null ;
55
- int id = link . Value < int > ( "id" ) ;
56
- if ( id != 0 )
57
+ foreach ( var link in links )
57
58
{
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 )
60
62
{
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 ) ;
63
78
}
64
79
}
65
80
66
- link [ "id" ] = guidUdi ? . ToString ( ) ;
81
+ return links ;
67
82
}
68
83
69
- return links . ToString ( Formatting . None ) ;
84
+ var rootLinks = ParseLinks ( JArray . Parse ( value ) ) ;
85
+
86
+ return rootLinks . ToString ( Formatting . None ) ;
70
87
}
71
88
72
89
/// <summary>
@@ -91,23 +108,36 @@ public void SetValue(IContentBase content, string alias, string value)
91
108
}
92
109
93
110
// 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 )
96
112
{
97
- int id = 0 ;
98
- if ( GuidUdi . TryParse ( link . Value < string > ( "id" ) , out GuidUdi guidUdi ) )
113
+ foreach ( var link in links )
99
114
{
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 ) )
102
117
{
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 ) ;
104
132
}
105
133
}
106
134
107
- link [ "id" ] = id ;
135
+ return links ;
108
136
}
109
137
110
- content . SetValue ( alias , links . ToString ( Formatting . None ) ) ;
138
+ var rootLinks = ParseLinks ( JArray . Parse ( value ) ) ;
139
+
140
+ content . SetValue ( alias , rootLinks . ToString ( Formatting . None ) ) ;
111
141
}
112
142
}
113
143
}
0 commit comments