22using Umbraco . Cms . Api . Delivery . Indexing . Selectors ;
33using Umbraco . Cms . Core . DeliveryApi ;
44using Umbraco . Cms . Core . DependencyInjection ;
5- using Umbraco . Cms . Core . Models . PublishedContent ;
65using Umbraco . Cms . Core . PublishedCache ;
76using Umbraco . Cms . Core . Services . Navigation ;
8- using Umbraco . Extensions ;
97
108namespace Umbraco . Cms . Api . Delivery . Querying . Selectors ;
119
1210public sealed class AncestorsSelector : QueryOptionBase , ISelectorHandler
1311{
14- private readonly IPublishedContentCache _publishedContentCache ;
1512 private readonly IDocumentNavigationQueryService _navigationQueryService ;
16- private readonly IRequestPreviewService _requestPreviewService ;
1713 private const string AncestorsSpecifier = "ancestors:" ;
1814
15+ [ Obsolete ( "Please use the non-obsolete constructor. Will be removed in V17." ) ]
1916 public AncestorsSelector (
2017 IPublishedContentCache publishedContentCache ,
2118 IRequestRoutingService requestRoutingService ,
2219 IDocumentNavigationQueryService navigationQueryService ,
2320 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 )
2528 {
26- _publishedContentCache = publishedContentCache ;
27- _navigationQueryService = navigationQueryService ;
28- _requestPreviewService = requestPreviewService ;
2929 }
3030
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." ) ]
3232 public AncestorsSelector (
3333 IPublishedContentCache publishedContentCache ,
3434 IRequestRoutingService requestRoutingService ,
3535 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 )
3743 {
3844 }
3945
4046 [ Obsolete ( "Use the constructor that takes all parameters. Scheduled for removal in V17." ) ]
4147 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 )
4376 {
4477 }
4578
@@ -53,7 +86,7 @@ public SelectorOption BuildSelectorOption(string selector)
5386 var fieldValue = selector [ AncestorsSpecifier . Length ..] ;
5487 Guid ? id = GetGuidFromQuery ( fieldValue ) ;
5588
56- if ( id is null )
89+ if ( id is null || _navigationQueryService . TryGetAncestorsKeys ( id . Value , out IEnumerable < Guid > ancestorKeys ) is false )
5790 {
5891 // Setting the Value to "" since that would yield no results.
5992 // It won't be appropriate to return null here since if we reached this,
@@ -65,24 +98,10 @@ public SelectorOption BuildSelectorOption(string selector)
6598 } ;
6699 }
67100
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-
82101 return new SelectorOption
83102 {
84103 FieldName = AncestorsSelectorIndexer . FieldName ,
85- Values = ancestorKeys
104+ Values = ancestorKeys . Select ( key => key . ToString ( "D" ) ) . ToArray ( )
86105 } ;
87106 }
88107}
0 commit comments