Being able to specify a start item in preview through Start-Item header (#14757)

This commit is contained in:
Elitsa Marinovska
2023-09-06 10:18:04 +02:00
committed by GitHub
parent 28d16f69ba
commit eef0da096e

View File

@@ -11,6 +11,7 @@ internal sealed class RequestStartItemProvider : RequestHeaderHandler, IRequestS
{
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
private readonly IVariationContextAccessor _variationContextAccessor;
private readonly IRequestPreviewService _requestPreviewService;
// this provider lifetime is Scope, so we can cache this as a field
private IPublishedContent? _requestedStartContent;
@@ -18,11 +19,13 @@ internal sealed class RequestStartItemProvider : RequestHeaderHandler, IRequestS
public RequestStartItemProvider(
IHttpContextAccessor httpContextAccessor,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor)
IVariationContextAccessor variationContextAccessor,
IRequestPreviewService requestPreviewService)
: base(httpContextAccessor)
{
_publishedSnapshotAccessor = publishedSnapshotAccessor;
_variationContextAccessor = variationContextAccessor;
_requestPreviewService = requestPreviewService;
}
/// <inheritdoc/>
@@ -45,7 +48,7 @@ internal sealed class RequestStartItemProvider : RequestHeaderHandler, IRequestS
return null;
}
IEnumerable<IPublishedContent> rootContent = publishedSnapshot.Content.GetAtRoot();
IEnumerable<IPublishedContent> rootContent = publishedSnapshot.Content.GetAtRoot(_requestPreviewService.IsPreview());
_requestedStartContent = Guid.TryParse(headerValue, out Guid key)
? rootContent.FirstOrDefault(c => c.Key == key)