Web.Routing - use UmbracoContext.ContentCache
This commit is contained in:
@@ -21,7 +21,6 @@ namespace Umbraco.Web.Routing
|
||||
/// Gets the nice url of a published content.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The Umbraco context.</param>
|
||||
/// <param name="contentCache">The content cache.</param>
|
||||
/// <param name="id">The published content id.</param>
|
||||
/// <param name="current">The current absolute url.</param>
|
||||
/// <param name="mode">The url mode.</param>
|
||||
@@ -31,7 +30,7 @@ namespace Umbraco.Web.Routing
|
||||
/// <c>absolute</c> is true, in which case the url is always absolute.</para>
|
||||
/// <para>If the provider is unable to provide a url, it should return <c>null</c>.</para>
|
||||
/// </remarks>
|
||||
public string GetUrl(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current, UrlProviderMode mode)
|
||||
public string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
|
||||
{
|
||||
return null; // we have nothing to say
|
||||
}
|
||||
@@ -44,7 +43,6 @@ namespace Umbraco.Web.Routing
|
||||
/// Gets the other urls of a published content.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The Umbraco context.</param>
|
||||
/// <param name="contentCache">The content cache.</param>
|
||||
/// <param name="id">The published content id.</param>
|
||||
/// <param name="current">The current absolute url.</param>
|
||||
/// <returns>The other urls for the published content.</returns>
|
||||
@@ -52,12 +50,12 @@ namespace Umbraco.Web.Routing
|
||||
/// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid
|
||||
/// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para>
|
||||
/// </remarks>
|
||||
public IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current)
|
||||
public IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
|
||||
{
|
||||
if (!FindByUrlAliasEnabled)
|
||||
return Enumerable.Empty<string>(); // we have nothing to say
|
||||
|
||||
var node = contentCache.GetById(umbracoContext, id);
|
||||
var node = umbracoContext.ContentCache.GetById(umbracoContext, id);
|
||||
string umbracoUrlName = null;
|
||||
if (node.HasProperty(Constants.Conventions.Content.UrlAlias))
|
||||
umbracoUrlName = node.GetPropertyValue<string>(Constants.Conventions.Content.UrlAlias);
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace Umbraco.Web.Routing
|
||||
/// Gets the nice url of a published content.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The Umbraco context.</param>
|
||||
/// <param name="contentCache">The content cache.</param>
|
||||
/// <param name="id">The published content id.</param>
|
||||
/// <param name="current">The current absolute url.</param>
|
||||
/// <param name="mode">The url mode.</param>
|
||||
@@ -30,7 +29,7 @@ namespace Umbraco.Web.Routing
|
||||
/// <para>The url is absolute or relative depending on <c>mode</c> and on <c>current</c>.</para>
|
||||
/// <para>If the provider is unable to provide a url, it should return <c>null</c>.</para>
|
||||
/// </remarks>
|
||||
public virtual string GetUrl(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current, UrlProviderMode mode)
|
||||
public virtual string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
|
||||
{
|
||||
DomainAndUri domainUri;
|
||||
string path;
|
||||
@@ -56,7 +55,7 @@ namespace Umbraco.Web.Routing
|
||||
else
|
||||
{
|
||||
// there was no route in the cache - create a route
|
||||
var node = contentCache.GetById(umbracoContext, id);
|
||||
var node = umbracoContext.ContentCache.GetById(umbracoContext, id);
|
||||
if (node == null)
|
||||
{
|
||||
LogHelper.Warn<DefaultUrlProvider>(
|
||||
@@ -84,7 +83,7 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
// no domain, respect HideTopLevelNodeFromPath for legacy purposes
|
||||
if (domainUri == null && global::umbraco.GlobalSettings.HideTopLevelNodeFromPath)
|
||||
ApplyHideTopLevelNodeFromPath(umbracoContext, contentCache, node, pathParts);
|
||||
ApplyHideTopLevelNodeFromPath(umbracoContext, node, pathParts);
|
||||
|
||||
// assemble the route
|
||||
pathParts.Reverse();
|
||||
@@ -108,7 +107,6 @@ namespace Umbraco.Web.Routing
|
||||
/// Gets the other urls of a published content.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The Umbraco context.</param>
|
||||
/// <param name="contentCache">The content cache.</param>
|
||||
/// <param name="id">The published content id.</param>
|
||||
/// <param name="current">The current absolute url.</param>
|
||||
/// <returns>The other urls for the published content.</returns>
|
||||
@@ -116,7 +114,7 @@ namespace Umbraco.Web.Routing
|
||||
/// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid
|
||||
/// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para>
|
||||
/// </remarks>
|
||||
public virtual IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current)
|
||||
public virtual IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
|
||||
{
|
||||
string path;
|
||||
IEnumerable<DomainAndUri> domainUris;
|
||||
@@ -137,7 +135,7 @@ namespace Umbraco.Web.Routing
|
||||
else
|
||||
{
|
||||
// there was no route in the cache - create a route
|
||||
var node = contentCache.GetById(umbracoContext, id);
|
||||
var node = umbracoContext.ContentCache.GetById(umbracoContext, id);
|
||||
if (node == null)
|
||||
{
|
||||
LogHelper.Warn<DefaultUrlProvider>(
|
||||
@@ -165,7 +163,7 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
// no domain, respect HideTopLevelNodeFromPath for legacy purposes
|
||||
if (domainUris == null && global::umbraco.GlobalSettings.HideTopLevelNodeFromPath)
|
||||
ApplyHideTopLevelNodeFromPath(umbracoContext, contentCache, node, pathParts);
|
||||
ApplyHideTopLevelNodeFromPath(umbracoContext, node, pathParts);
|
||||
|
||||
// assemble the route
|
||||
pathParts.Reverse();
|
||||
@@ -273,7 +271,7 @@ namespace Umbraco.Web.Routing
|
||||
return uris.Select(UriUtility.UriFromUmbraco);
|
||||
}
|
||||
|
||||
static void ApplyHideTopLevelNodeFromPath(UmbracoContext umbracoContext, IPublishedContentCache contentCache, Core.Models.IPublishedContent node, IList<string> pathParts)
|
||||
static void ApplyHideTopLevelNodeFromPath(UmbracoContext umbracoContext, Core.Models.IPublishedContent node, IList<string> pathParts)
|
||||
{
|
||||
// in theory if hideTopLevelNodeFromPath is true, then there should be only once
|
||||
// top-level node, or else domains should be assigned. but for backward compatibility
|
||||
@@ -285,7 +283,7 @@ namespace Umbraco.Web.Routing
|
||||
// that's the way it works pre-4.10 and we try to be backward compat for the time being
|
||||
if (node.Parent == null)
|
||||
{
|
||||
var rootNode = contentCache.GetByRoute(umbracoContext, "/", true);
|
||||
var rootNode = umbracoContext.ContentCache.GetByRoute(umbracoContext, "/", true);
|
||||
if (rootNode.Id == node.Id) // remove only if we're the default node
|
||||
pathParts.RemoveAt(pathParts.Count - 1);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace Umbraco.Web.Routing
|
||||
/// Gets the nice url of a published content.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The Umbraco context.</param>
|
||||
/// <param name="contentCache">The content cache.</param>
|
||||
/// <param name="id">The published content id.</param>
|
||||
/// <param name="current">The current absolute url.</param>
|
||||
/// <param name="mode">The url mode.</param>
|
||||
@@ -22,13 +21,12 @@ namespace Umbraco.Web.Routing
|
||||
/// <para>The url is absolute or relative depending on <c>mode</c> and on <c>current</c>.</para>
|
||||
/// <para>If the provider is unable to provide a url, it should return <c>null</c>.</para>
|
||||
/// </remarks>
|
||||
string GetUrl(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current, UrlProviderMode mode);
|
||||
string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the other urls of a published content.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The Umbraco context.</param>
|
||||
/// <param name="contentCache">The content cache.</param>
|
||||
/// <param name="id">The published content id.</param>
|
||||
/// <param name="current">The current absolute url.</param>
|
||||
/// <returns>The other urls for the published content.</returns>
|
||||
@@ -36,6 +34,6 @@ namespace Umbraco.Web.Routing
|
||||
/// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid
|
||||
/// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para>
|
||||
/// </remarks>
|
||||
IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current);
|
||||
IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace Umbraco.Web.Routing
|
||||
/// </remarks>
|
||||
public string GetUrl(int id, Uri current, UrlProviderMode mode)
|
||||
{
|
||||
var url = _urlProviders.Select(provider => provider.GetUrl(_umbracoContext, _umbracoContext.ContentCache, id, current, mode))
|
||||
var url = _urlProviders.Select(provider => provider.GetUrl(_umbracoContext, id, current, mode))
|
||||
.FirstOrDefault(u => u != null);
|
||||
return url ?? "#"; // legacy wants this
|
||||
}
|
||||
@@ -151,7 +151,7 @@ namespace Umbraco.Web.Routing
|
||||
public IEnumerable<string> GetOtherUrls(int id, Uri current)
|
||||
{
|
||||
// providers can return null or an empty list or a non-empty list, be prepared
|
||||
var urls = _urlProviders.SelectMany(provider => provider.GetOtherUrls(_umbracoContext, _umbracoContext.ContentCache, id, current) ?? Enumerable.Empty<string>());
|
||||
var urls = _urlProviders.SelectMany(provider => provider.GetOtherUrls(_umbracoContext, id, current) ?? Enumerable.Empty<string>());
|
||||
|
||||
return urls;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user