1
- using System ;
2
- using System . Collections . Generic ;
3
- using System . Text . RegularExpressions ;
4
- using Microsoft . Extensions . Logging ;
1
+ using Microsoft . Extensions . Logging ;
5
2
using Newtonsoft . Json ;
6
3
using Newtonsoft . Json . Linq ;
4
+ using System ;
5
+ using System . Collections . Generic ;
6
+ using System . Text . RegularExpressions ;
7
7
using Umbraco . Cms . Core ;
8
8
using Umbraco . Cms . Core . Deploy ;
9
9
using Umbraco . Cms . Core . Models ;
10
10
using Umbraco . Cms . Core . PropertyEditors ;
11
11
using Umbraco . Cms . Core . Services ;
12
+ using Umbraco . Deploy . Core ;
13
+ using Umbraco . Deploy . Core . Connectors . ValueConnectors ;
12
14
using Umbraco . Extensions ;
13
15
14
16
namespace Umbraco . Deploy . Contrib . ValueConnectors
15
17
{
16
- public class MultiUrlPickerValueConnector : IValueConnector
18
+ public class MultiUrlPickerValueConnector : ValueConnectorBase
17
19
{
18
20
private readonly IEntityService _entityService ;
19
21
private readonly IMediaService _mediaService ;
@@ -23,6 +25,12 @@ public class MultiUrlPickerValueConnector : IValueConnector
23
25
// Used to fetch the udi from a umb://-based url
24
26
private static readonly Regex MediaUdiSrcRegex = new Regex ( @"(?<udi>umb://media/[A-z0-9]+)" , RegexOptions . Compiled | RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ;
25
27
28
+ /// <inheritdoc />
29
+ public override IEnumerable < string > PropertyEditorAliases { get ; } = new [ ]
30
+ {
31
+ "Umbraco.MultiUrlPicker"
32
+ } ;
33
+
26
34
/// <summary>
27
35
/// Initializes a new instance of the <see cref="MultiUrlPickerValueConnector"/> class.
28
36
/// Source found here: https://github.com/rasmusjp/umbraco-multi-url-picker
@@ -57,7 +65,7 @@ public MultiUrlPickerValueConnector(
57
65
_mediaUrlGenerators = mediaUrlGenerators ;
58
66
}
59
67
60
- public string ToArtifact ( object value , IPropertyType propertyType , ICollection < ArtifactDependency > dependencies )
68
+ public sealed override string ToArtifact ( object value , IPropertyType propertyType , ICollection < ArtifactDependency > dependencies , IContextCache contextCache )
61
69
{
62
70
var svalue = value as string ;
63
71
if ( string . IsNullOrWhiteSpace ( svalue ) )
@@ -75,11 +83,9 @@ public string ToArtifact(object value, IPropertyType propertyType, ICollection<A
75
83
foreach ( var link in links )
76
84
{
77
85
var isMedia = link [ "isMedia" ] != null ;
78
- int intId ;
79
- string url ;
80
- GuidUdi guidUdi ;
86
+
81
87
// Only do processing if the Id is set on the element. OR if the url is set and its a media item
82
- if ( TryParseJTokenAttr ( link , "id" , out intId ) )
88
+ if ( TryParseJTokenAttr ( link , "id" , out int intId ) )
83
89
{
84
90
// Checks weather we are resolving a media item or a document
85
91
var objectTypeId = isMedia
@@ -92,15 +98,16 @@ public string ToArtifact(object value, IPropertyType propertyType, ICollection<A
92
98
continue ;
93
99
94
100
var udi = new GuidUdi ( entityType , guidAttempt . Result ) ;
101
+
95
102
// Add the artifact dependency
96
103
dependencies . Add ( new ArtifactDependency ( udi , false , ArtifactDependencyMode . Exist ) ) ;
97
104
98
105
// Set the Id attribute to the udi
99
106
link [ "id" ] = udi . ToString ( ) ;
100
107
}
101
- else if ( TryParseJTokenAttr ( link , "udi" , out guidUdi ) )
108
+ else if ( TryParseJTokenAttr ( link , "udi" , out GuidUdi guidUdi ) )
102
109
{
103
- var entityExists = _entityService . Exists ( guidUdi . Guid ) ;
110
+ var entityExists = contextCache . EntityExists ( _entityService , guidUdi . Guid ) ;
104
111
if ( ! entityExists )
105
112
{
106
113
continue ;
@@ -109,7 +116,7 @@ public string ToArtifact(object value, IPropertyType propertyType, ICollection<A
109
116
// Add the artifact dependency
110
117
dependencies . Add ( new ArtifactDependency ( guidUdi , false , ArtifactDependencyMode . Exist ) ) ;
111
118
}
112
- else if ( isMedia && TryParseJTokenAttr ( link , "url" , out url ) )
119
+ else if ( isMedia && TryParseJTokenAttr ( link , "url" , out string url ) )
113
120
{
114
121
// This state can happen due to an issue in RJP.MultiUrlPicker(or our linkPicker in RTE which it relies on),
115
122
// where you edit a media link, and just hit "Select".
@@ -150,10 +157,11 @@ public string ToArtifact(object value, IPropertyType propertyType, ICollection<A
150
157
: UmbracoObjectTypes . Document ;
151
158
var entityType = isMedia ? Constants . UdiEntityType . Media : Constants . UdiEntityType . Document ;
152
159
153
- var guidAttempt = _entityService . GetKey ( intId , objectTypeId ) ;
160
+ var guidAttempt = contextCache . GetEntityKeyById ( _entityService , intId , objectTypeId ) ;
154
161
if ( guidAttempt . Success )
155
162
{
156
163
var udi = new GuidUdi ( entityType , guidAttempt . Result ) ;
164
+
157
165
// Add the artifact dependency
158
166
dependencies . Add ( new ArtifactDependency ( udi , false , ArtifactDependencyMode . Exist ) ) ;
159
167
@@ -163,8 +171,7 @@ public string ToArtifact(object value, IPropertyType propertyType, ICollection<A
163
171
}
164
172
else if ( TryParseJTokenAttr ( link , "udi" , out guidUdi ) )
165
173
{
166
- var entity = _entityService . Get ( guidUdi . Guid , UdiEntityTypeHelper . ToUmbracoObjectType ( guidUdi . EntityType ) ) ;
167
- if ( entity != null )
174
+ if ( contextCache . EntityExists ( _entityService , guidUdi . Guid ) )
168
175
{
169
176
// Add the artifact dependency
170
177
dependencies . Add ( new ArtifactDependency ( guidUdi , false , ArtifactDependencyMode . Exist ) ) ;
@@ -194,7 +201,7 @@ public string ToArtifact(object value, IPropertyType propertyType, ICollection<A
194
201
return string . Empty ;
195
202
}
196
203
197
- public object FromArtifact ( string value , IPropertyType propertyType , object currentValue )
204
+ public sealed override object FromArtifact ( string value , IPropertyType propertyType , object currentValue , IContextCache contextCache )
198
205
{
199
206
if ( string . IsNullOrWhiteSpace ( value ) )
200
207
{
@@ -224,7 +231,7 @@ public object FromArtifact(string value, IPropertyType propertyType, object curr
224
231
// Get the Id corresponding to the Guid
225
232
// it *should* succeed when deploying, due to dependencies management
226
233
// nevertheless, assume it can fail, and then create an invalid localLink
227
- var idAttempt = _entityService . GetId ( udi . Guid , nodeObjectType ) ;
234
+ var idAttempt = contextCache . GetEntityIdByKey ( _entityService , udi . Guid , nodeObjectType ) ;
228
235
if ( idAttempt )
229
236
link [ "id" ] = idAttempt . Success ? idAttempt . Result : 0 ;
230
237
}
@@ -269,7 +276,7 @@ public object FromArtifact(string value, IPropertyType propertyType, object curr
269
276
// Get the Id corresponding to the Guid
270
277
// it *should* succeed when deploying, due to dependencies management
271
278
// nevertheless, assume it can fail, and then create an invalid localLink
272
- var idAttempt = _entityService . GetId ( udi . Guid , nodeObjectType ) ;
279
+ var idAttempt = contextCache . GetEntityIdByKey ( _entityService , udi . Guid , nodeObjectType ) ;
273
280
if ( idAttempt )
274
281
link [ "id" ] = idAttempt . Success ? idAttempt . Result : 0 ;
275
282
}
@@ -301,9 +308,6 @@ public object FromArtifact(string value, IPropertyType propertyType, object curr
301
308
return value ;
302
309
}
303
310
304
- /// <inheritdoc/>
305
- public virtual IEnumerable < string > PropertyEditorAliases => new [ ] { "RJP.MultiUrlPicker" , "Umbraco.MultiUrlPicker" } ;
306
-
307
311
private bool TryParseJTokenAttr ( JToken link , string attrName , out int attrValue )
308
312
{
309
313
if ( link [ attrName ] != null )
0 commit comments