2021-01-06 17:04:35 +11:00
|
|
|
|
|
|
|
|
using Umbraco.Core.Models.PublishedContent;
|
|
|
|
|
|
2020-02-28 11:15:25 +01:00
|
|
|
namespace Umbraco.Web.Routing
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This looks up a document by checking for the umbPageId of a request/query string
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This is used by library.RenderTemplate and also some of the macro rendering functionality like in
|
|
|
|
|
/// macroResultWrapper.aspx
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public class ContentFinderByPageIdQuery : IContentFinder
|
|
|
|
|
{
|
2020-02-28 11:15:25 +01:00
|
|
|
private readonly IRequestAccessor _requestAccessor;
|
2021-01-06 17:04:35 +11:00
|
|
|
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
2020-02-10 13:09:26 +01:00
|
|
|
|
2021-01-06 17:04:35 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="ContentFinderByPageIdQuery"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ContentFinderByPageIdQuery(IRequestAccessor requestAccessor, IUmbracoContextAccessor umbracoContextAccessor)
|
2020-02-10 13:09:26 +01:00
|
|
|
{
|
2021-01-06 17:04:35 +11:00
|
|
|
_requestAccessor = requestAccessor ?? throw new System.ArgumentNullException(nameof(requestAccessor));
|
|
|
|
|
_umbracoContextAccessor = umbracoContextAccessor ?? throw new System.ArgumentNullException(nameof(umbracoContextAccessor));
|
2020-02-10 13:09:26 +01:00
|
|
|
}
|
|
|
|
|
|
2021-01-06 17:04:35 +11:00
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public bool TryFindContent(IPublishedRequestBuilder frequest)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2021-01-06 17:04:35 +11:00
|
|
|
IUmbracoContext umbCtx = _umbracoContextAccessor.UmbracoContext;
|
|
|
|
|
if (umbCtx == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (int.TryParse(_requestAccessor.GetRequestValue("umbPageID"), out int pageId))
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2021-01-06 17:04:35 +11:00
|
|
|
IPublishedContent doc = umbCtx.Content.GetById(pageId);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
|
|
|
if (doc != null)
|
|
|
|
|
{
|
2021-01-06 17:04:35 +11:00
|
|
|
frequest.SetPublishedContent(doc);
|
2018-06-29 19:52:40 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-06 17:04:35 +11:00
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|