From 1d4589bb9f0b9dc30fcb452655757df540eaffd1 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Mon, 29 Apr 2024 19:57:43 +0300 Subject: [PATCH] Autoroute handle prefix as constant (#15918) --- .../Razor/AutoroutePartRazorHelperExtensions.cs | 3 ++- .../OrchardCore.Templates/Controllers/PreviewController.cs | 3 ++- .../OrchardCore.Templates/OrchardCore.Templates.csproj | 1 + .../OrchardCore.Autoroute.Core/AutorouteConstants.cs | 6 ++++++ .../Services/AutorouteHandleProvider.cs | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 src/OrchardCore/OrchardCore.Autoroute.Core/AutorouteConstants.cs diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Razor/AutoroutePartRazorHelperExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Razor/AutoroutePartRazorHelperExtensions.cs index 119d7d6087b..49ba03b38d0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Razor/AutoroutePartRazorHelperExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Razor/AutoroutePartRazorHelperExtensions.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using OrchardCore; +using OrchardCore.Autoroute; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Routing; @@ -24,7 +25,7 @@ public static async Task GetContentItemIdBySlugAsync(this IOrchardHelper } // Provided for backwards compatability and avoiding confusion. - if (slug.StartsWith("slug:", StringComparison.OrdinalIgnoreCase)) + if (slug.StartsWith(AutorouteConstants.SlugPrefix, StringComparison.OrdinalIgnoreCase)) { slug = slug[5..]; } diff --git a/src/OrchardCore.Modules/OrchardCore.Templates/Controllers/PreviewController.cs b/src/OrchardCore.Modules/OrchardCore.Templates/Controllers/PreviewController.cs index 6704c665dd4..adc4723102d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Templates/Controllers/PreviewController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Templates/Controllers/PreviewController.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using OrchardCore.Autoroute; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display; using OrchardCore.ContentPreview; @@ -80,7 +81,7 @@ public async Task Render() handle = (index < 0 ? handle : handle[_homeUrl.Length..]) .ToUriComponents(UriFormat.SafeUnescaped); - contentItemId = await _contentHandleManager.GetContentItemIdAsync("slug:" + handle); + contentItemId = await _contentHandleManager.GetContentItemIdAsync(AutorouteConstants.SlugPrefix + handle); } if (string.IsNullOrEmpty(contentItemId)) diff --git a/src/OrchardCore.Modules/OrchardCore.Templates/OrchardCore.Templates.csproj b/src/OrchardCore.Modules/OrchardCore.Templates/OrchardCore.Templates.csproj index 90597af0570..907fa152373 100644 --- a/src/OrchardCore.Modules/OrchardCore.Templates/OrchardCore.Templates.csproj +++ b/src/OrchardCore.Modules/OrchardCore.Templates/OrchardCore.Templates.csproj @@ -16,6 +16,7 @@ + diff --git a/src/OrchardCore/OrchardCore.Autoroute.Core/AutorouteConstants.cs b/src/OrchardCore/OrchardCore.Autoroute.Core/AutorouteConstants.cs new file mode 100644 index 00000000000..269bd556108 --- /dev/null +++ b/src/OrchardCore/OrchardCore.Autoroute.Core/AutorouteConstants.cs @@ -0,0 +1,6 @@ +namespace OrchardCore.Autoroute; + +public class AutorouteConstants +{ + public const string SlugPrefix = "slug:"; +} diff --git a/src/OrchardCore/OrchardCore.Autoroute.Core/Services/AutorouteHandleProvider.cs b/src/OrchardCore/OrchardCore.Autoroute.Core/Services/AutorouteHandleProvider.cs index eb6a34b5f15..ec9c5034d45 100644 --- a/src/OrchardCore/OrchardCore.Autoroute.Core/Services/AutorouteHandleProvider.cs +++ b/src/OrchardCore/OrchardCore.Autoroute.Core/Services/AutorouteHandleProvider.cs @@ -15,7 +15,7 @@ public class AutorouteHandleProvider : IContentHandleProvider public async Task GetContentItemIdAsync(string handle) { - if (handle.StartsWith("slug:", StringComparison.OrdinalIgnoreCase)) + if (handle.StartsWith(AutorouteConstants.SlugPrefix, StringComparison.OrdinalIgnoreCase)) { handle = handle[5..];