Added configuration to allow RTL cultures to opt-in to reverse the url hierarchy (#12635)

* Added configuration to allow RTL cultures to opt-in to reverse the url hierarchy.

https://github.com/umbraco/Umbraco-CMS/issues/12621

* Fixed bug.. There is difference between array.Reverse (Linq) and list.Reverse (native)

* formatting
This commit is contained in:
Bjarke Berg
2022-06-30 14:08:13 +02:00
committed by GitHub
parent 5eb5cb7e2b
commit be1fddb9be
2 changed files with 33 additions and 3 deletions

View File

@@ -33,6 +33,7 @@ public class GlobalSettings
internal const string StaticDistributedLockingWriteLockDefaultTimeout = "00:00:05";
internal const bool StaticSanitizeTinyMce = false;
internal const int StaticMainDomReleaseSignalPollingInterval = 2000;
private const bool StaticForceCombineUrlPathLeftToRight = true;
/// <summary>
/// Gets or sets a value for the reserved URLs (must end with a comma).
@@ -226,7 +227,25 @@ public class GlobalSettings
TimeSpan.Parse(StaticDistributedLockingWriteLockDefaultTimeout);
/// <summary>
/// Gets or sets a value representing the DistributedLockingMechanism to use.
/// Gets or sets a value representing the DistributedLockingMechanism to use.
/// </summary>
public string DistributedLockingMechanism { get; set; } = string.Empty;
/// <summary>
/// Force url paths to be left to right, even when the culture has right to left text
/// </summary>
/// <example>
/// For the following hierarchy
/// - Root (/ar)
/// - 1 (/ar/1)
/// - 2 (/ar/1/2)
/// - 3 (/ar/1/2/3)
/// - 3 (/ar/1/2/3/4)
/// When forced
/// - https://www.umbraco.com/ar/1/2/3/4
/// when not
/// - https://www.umbraco.com/ar/4/3/2/1
/// </example>
[DefaultValue(StaticForceCombineUrlPathLeftToRight)]
public bool ForceCombineUrlPathLeftToRight { get; set; } = StaticForceCombineUrlPathLeftToRight;
}

View File

@@ -87,6 +87,12 @@ public class ContentCache : PublishedCacheBase, IPublishedContentCache, INavigab
IPublishedContent? content;
if ((!_globalSettings.ForceCombineUrlPathLeftToRight
&& CultureInfo.GetCultureInfo(culture ?? _globalSettings.DefaultUILanguage).TextInfo.IsRightToLeft))
{
parts = parts.Reverse().ToArray();
}
if (startNodeId > 0)
{
// if in a domain then start with the root node of the domain
@@ -190,8 +196,13 @@ public class ContentCache : PublishedCacheBase, IPublishedContentCache, INavigab
ApplyHideTopLevelNodeFromPath(node, pathParts, preview);
}
// assemble the route
pathParts.Reverse();
// assemble the route- We only have to reverse for left to right languages
if ((_globalSettings.ForceCombineUrlPathLeftToRight
|| !CultureInfo.GetCultureInfo(culture ?? _globalSettings.DefaultUILanguage).TextInfo.IsRightToLeft))
{
pathParts.Reverse();
}
var path = "/" + string.Join("/", pathParts); // will be "/" or "/foo" or "/foo/bar" etc
// prefix the root node id containing the domain if it exists (this is a standard way of creating route paths)