8
8
using Umbraco . Core . Logging ;
9
9
using Umbraco . Core . Models ;
10
10
using Umbraco . Core . Services ;
11
+ using Umbraco . Deploy . Connectors . ValueConnectors ;
12
+ using Umbraco . Deploy . Core ;
11
13
12
14
namespace Umbraco . Deploy . Contrib . Connectors . ValueConnectors
13
15
{
14
- public class MultiUrlPickerValueConnector : IValueConnector
16
+ public class MultiUrlPickerValueConnector : ValueConnectorBase
15
17
{
16
18
private readonly IEntityService _entityService ;
17
19
private readonly IMediaService _mediaService ;
@@ -20,6 +22,12 @@ public class MultiUrlPickerValueConnector : IValueConnector
20
22
// Used to fetch the udi from a umb://-based url
21
23
private static readonly Regex MediaUdiSrcRegex = new Regex ( @"(?<udi>umb://media/[A-z0-9]+)" , RegexOptions . Compiled | RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ;
22
24
25
+ /// <inheritdoc />
26
+ public override IEnumerable < string > PropertyEditorAliases { get ; } = new [ ]
27
+ {
28
+ "Umbraco.MultiUrlPicker"
29
+ } ;
30
+
23
31
/// <summary>
24
32
/// Initializes a new instance of the <see cref="MultiUrlPickerValueConnector"/> class.
25
33
/// Source found here: https://github.com/rasmusjp/umbraco-multi-url-picker
@@ -49,7 +57,7 @@ public MultiUrlPickerValueConnector(IEntityService entityService, IMediaService
49
57
_logger = logger ;
50
58
}
51
59
52
- public string ToArtifact ( object value , PropertyType propertyType , ICollection < ArtifactDependency > dependencies )
60
+ public sealed override string ToArtifact ( object value , PropertyType propertyType , ICollection < ArtifactDependency > dependencies , IContextCache contextCache )
53
61
{
54
62
var svalue = value as string ;
55
63
if ( string . IsNullOrWhiteSpace ( svalue ) )
@@ -67,11 +75,9 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
67
75
foreach ( var link in links )
68
76
{
69
77
var isMedia = link [ "isMedia" ] != null ;
70
- int intId ;
71
- string url ;
72
- GuidUdi guidUdi ;
78
+
73
79
// Only do processing if the Id is set on the element. OR if the url is set and its a media item
74
- if ( TryParseJTokenAttr ( link , "id" , out intId ) )
80
+ if ( TryParseJTokenAttr ( link , "id" , out int intId ) )
75
81
{
76
82
// Checks weather we are resolving a media item or a document
77
83
var objectTypeId = isMedia
@@ -84,15 +90,16 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
84
90
continue ;
85
91
86
92
var udi = new GuidUdi ( entityType , guidAttempt . Result ) ;
93
+
87
94
// Add the artifact dependency
88
95
dependencies . Add ( new ArtifactDependency ( udi , false , ArtifactDependencyMode . Exist ) ) ;
89
96
90
97
// Set the Id attribute to the udi
91
98
link [ "id" ] = udi . ToString ( ) ;
92
99
}
93
- else if ( TryParseJTokenAttr ( link , "udi" , out guidUdi ) )
100
+ else if ( TryParseJTokenAttr ( link , "udi" , out GuidUdi guidUdi ) )
94
101
{
95
- var entityExists = _entityService . Exists ( guidUdi . Guid ) ;
102
+ var entityExists = contextCache . EntityExists ( _entityService , guidUdi . Guid ) ;
96
103
if ( ! entityExists )
97
104
{
98
105
continue ;
@@ -101,7 +108,7 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
101
108
// Add the artifact dependency
102
109
dependencies . Add ( new ArtifactDependency ( guidUdi , false , ArtifactDependencyMode . Exist ) ) ;
103
110
}
104
- else if ( isMedia && TryParseJTokenAttr ( link , "url" , out url ) )
111
+ else if ( isMedia && TryParseJTokenAttr ( link , "url" , out string url ) )
105
112
{
106
113
// This state can happen due to an issue in RJP.MultiUrlPicker(or our linkPicker in RTE which it relies on),
107
114
// where you edit a media link, and just hit "Select".
@@ -142,10 +149,11 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
142
149
: UmbracoObjectTypes . Document ;
143
150
var entityType = isMedia ? Constants . UdiEntityType . Media : Constants . UdiEntityType . Document ;
144
151
145
- var guidAttempt = _entityService . GetKey ( intId , objectTypeId ) ;
152
+ var guidAttempt = contextCache . GetEntityKeyById ( _entityService , intId , objectTypeId ) ;
146
153
if ( guidAttempt . Success )
147
154
{
148
155
var udi = new GuidUdi ( entityType , guidAttempt . Result ) ;
156
+
149
157
// Add the artifact dependency
150
158
dependencies . Add ( new ArtifactDependency ( udi , false , ArtifactDependencyMode . Exist ) ) ;
151
159
@@ -155,8 +163,7 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
155
163
}
156
164
else if ( TryParseJTokenAttr ( link , "udi" , out guidUdi ) )
157
165
{
158
- var entity = _entityService . Get ( guidUdi . Guid , Constants . UdiEntityType . ToUmbracoObjectType ( guidUdi . EntityType ) ) ;
159
- if ( entity != null )
166
+ if ( contextCache . EntityExists ( _entityService , guidUdi . Guid ) )
160
167
{
161
168
// Add the artifact dependency
162
169
dependencies . Add ( new ArtifactDependency ( guidUdi , false , ArtifactDependencyMode . Exist ) ) ;
@@ -186,7 +193,7 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
186
193
return string . Empty ;
187
194
}
188
195
189
- public object FromArtifact ( string value , PropertyType propertyType , object currentValue )
196
+ public sealed override object FromArtifact ( string value , PropertyType propertyType , object currentValue , IContextCache contextCache )
190
197
{
191
198
if ( string . IsNullOrWhiteSpace ( value ) )
192
199
{
@@ -216,7 +223,7 @@ public object FromArtifact(string value, PropertyType propertyType, object curre
216
223
// Get the Id corresponding to the Guid
217
224
// it *should* succeed when deploying, due to dependencies management
218
225
// nevertheless, assume it can fail, and then create an invalid localLink
219
- var idAttempt = _entityService . GetId ( udi . Guid , nodeObjectType ) ;
226
+ var idAttempt = contextCache . GetEntityIdByKey ( _entityService , udi . Guid , nodeObjectType ) ;
220
227
if ( idAttempt )
221
228
link [ "id" ] = idAttempt . Success ? idAttempt . Result : 0 ;
222
229
}
@@ -261,7 +268,7 @@ public object FromArtifact(string value, PropertyType propertyType, object curre
261
268
// Get the Id corresponding to the Guid
262
269
// it *should* succeed when deploying, due to dependencies management
263
270
// nevertheless, assume it can fail, and then create an invalid localLink
264
- var idAttempt = _entityService . GetId ( udi . Guid , nodeObjectType ) ;
271
+ var idAttempt = contextCache . GetEntityIdByKey ( _entityService , udi . Guid , nodeObjectType ) ;
265
272
if ( idAttempt )
266
273
link [ "id" ] = idAttempt . Success ? idAttempt . Result : 0 ;
267
274
}
@@ -293,9 +300,6 @@ public object FromArtifact(string value, PropertyType propertyType, object curre
293
300
return value ;
294
301
}
295
302
296
- /// <inheritdoc/>
297
- public virtual IEnumerable < string > PropertyEditorAliases => new [ ] { "RJP.MultiUrlPicker" , "Umbraco.MultiUrlPicker" } ;
298
-
299
303
private bool TryParseJTokenAttr ( JToken link , string attrName , out int attrValue )
300
304
{
301
305
if ( link [ attrName ] != null )
0 commit comments