2
2
using Umbraco . Cms . Api . Delivery . Indexing . Selectors ;
3
3
using Umbraco . Cms . Core . DeliveryApi ;
4
4
using Umbraco . Cms . Core . DependencyInjection ;
5
- using Umbraco . Cms . Core . Models . PublishedContent ;
6
5
using Umbraco . Cms . Core . PublishedCache ;
7
6
using Umbraco . Cms . Core . Services . Navigation ;
8
- using Umbraco . Extensions ;
9
7
10
8
namespace Umbraco . Cms . Api . Delivery . Querying . Selectors ;
11
9
12
10
public sealed class AncestorsSelector : QueryOptionBase , ISelectorHandler
13
11
{
14
- private readonly IPublishedContentCache _publishedContentCache ;
15
12
private readonly IDocumentNavigationQueryService _navigationQueryService ;
16
- private readonly IRequestPreviewService _requestPreviewService ;
17
13
private const string AncestorsSpecifier = "ancestors:" ;
18
14
15
+ [ Obsolete ( "Please use the non-obsolete constructor. Will be removed in V17." ) ]
19
16
public AncestorsSelector (
20
17
IPublishedContentCache publishedContentCache ,
21
18
IRequestRoutingService requestRoutingService ,
22
19
IDocumentNavigationQueryService navigationQueryService ,
23
20
IRequestPreviewService requestPreviewService )
24
- : base ( publishedContentCache , requestRoutingService )
21
+ : this (
22
+ requestRoutingService ,
23
+ StaticServiceProvider . Instance . GetRequiredService < IPublishedContentCache > ( ) ,
24
+ StaticServiceProvider . Instance . GetRequiredService < IRequestPreviewService > ( ) ,
25
+ StaticServiceProvider . Instance . GetRequiredService < IRequestCultureService > ( ) ,
26
+ StaticServiceProvider . Instance . GetRequiredService < IApiDocumentUrlService > ( ) ,
27
+ navigationQueryService )
25
28
{
26
- _publishedContentCache = publishedContentCache ;
27
- _navigationQueryService = navigationQueryService ;
28
- _requestPreviewService = requestPreviewService ;
29
29
}
30
30
31
- [ Obsolete ( "Use the constructor that takes all parameters. Scheduled for removal in V17." ) ]
31
+ [ Obsolete ( "Please use the non-obsolete constructor. Will be removed in V17." ) ]
32
32
public AncestorsSelector (
33
33
IPublishedContentCache publishedContentCache ,
34
34
IRequestRoutingService requestRoutingService ,
35
35
IDocumentNavigationQueryService navigationQueryService )
36
- : this ( publishedContentCache , requestRoutingService , navigationQueryService , StaticServiceProvider . Instance . GetRequiredService < IRequestPreviewService > ( ) )
36
+ : this (
37
+ requestRoutingService ,
38
+ StaticServiceProvider . Instance . GetRequiredService < IPublishedContentCache > ( ) ,
39
+ StaticServiceProvider . Instance . GetRequiredService < IRequestPreviewService > ( ) ,
40
+ StaticServiceProvider . Instance . GetRequiredService < IRequestCultureService > ( ) ,
41
+ StaticServiceProvider . Instance . GetRequiredService < IApiDocumentUrlService > ( ) ,
42
+ navigationQueryService )
37
43
{
38
44
}
39
45
40
46
[ Obsolete ( "Use the constructor that takes all parameters. Scheduled for removal in V17." ) ]
41
47
public AncestorsSelector ( IPublishedContentCache publishedContentCache , IRequestRoutingService requestRoutingService )
42
- : this ( publishedContentCache , requestRoutingService , StaticServiceProvider . Instance . GetRequiredService < IDocumentNavigationQueryService > ( ) )
48
+ : this (
49
+ requestRoutingService ,
50
+ StaticServiceProvider . Instance . GetRequiredService < IPublishedContentCache > ( ) ,
51
+ StaticServiceProvider . Instance . GetRequiredService < IRequestPreviewService > ( ) ,
52
+ StaticServiceProvider . Instance . GetRequiredService < IRequestCultureService > ( ) ,
53
+ StaticServiceProvider . Instance . GetRequiredService < IApiDocumentUrlService > ( ) ,
54
+ StaticServiceProvider . Instance . GetRequiredService < IDocumentNavigationQueryService > ( ) )
55
+ {
56
+ }
57
+
58
+ public AncestorsSelector (
59
+ IRequestRoutingService requestRoutingService ,
60
+ IRequestPreviewService requestPreviewService ,
61
+ IRequestCultureService requestCultureService ,
62
+ IApiDocumentUrlService apiDocumentUrlService ,
63
+ IDocumentNavigationQueryService navigationQueryService )
64
+ : base ( requestRoutingService , requestPreviewService , requestCultureService , apiDocumentUrlService )
65
+ => _navigationQueryService = navigationQueryService ;
66
+
67
+ [ Obsolete ( "Use the constructor that takes all parameters. Scheduled for removal in V17." ) ]
68
+ public AncestorsSelector (
69
+ IRequestRoutingService requestRoutingService ,
70
+ IPublishedContentCache publishedContentCache ,
71
+ IRequestPreviewService requestPreviewService ,
72
+ IRequestCultureService requestCultureService ,
73
+ IApiDocumentUrlService apiDocumentUrlService ,
74
+ IDocumentNavigationQueryService navigationQueryService )
75
+ : this ( requestRoutingService , requestPreviewService , requestCultureService , apiDocumentUrlService , navigationQueryService )
43
76
{
44
77
}
45
78
@@ -53,7 +86,7 @@ public SelectorOption BuildSelectorOption(string selector)
53
86
var fieldValue = selector [ AncestorsSpecifier . Length ..] ;
54
87
Guid ? id = GetGuidFromQuery ( fieldValue ) ;
55
88
56
- if ( id is null )
89
+ if ( id is null || _navigationQueryService . TryGetAncestorsKeys ( id . Value , out IEnumerable < Guid > ancestorKeys ) is false )
57
90
{
58
91
// Setting the Value to "" since that would yield no results.
59
92
// It won't be appropriate to return null here since if we reached this,
@@ -65,24 +98,10 @@ public SelectorOption BuildSelectorOption(string selector)
65
98
} ;
66
99
}
67
100
68
- IPublishedContent ? contentItem = _publishedContentCache . GetById ( _requestPreviewService . IsPreview ( ) , id . Value ) ;
69
-
70
- if ( contentItem is null )
71
- {
72
- // no such content item, make sure the selector does not yield any results
73
- return new SelectorOption
74
- {
75
- FieldName = AncestorsSelectorIndexer . FieldName ,
76
- Values = Array . Empty < string > ( )
77
- } ;
78
- }
79
-
80
- var ancestorKeys = contentItem . Ancestors ( _publishedContentCache , _navigationQueryService ) . Select ( a => a . Key . ToString ( "D" ) ) . ToArray ( ) ;
81
-
82
101
return new SelectorOption
83
102
{
84
103
FieldName = AncestorsSelectorIndexer . FieldName ,
85
- Values = ancestorKeys
104
+ Values = ancestorKeys . Select ( key => key . ToString ( "D" ) ) . ToArray ( )
86
105
} ;
87
106
}
88
107
}
0 commit comments