Skip to content

Commit

Permalink
Autoroute handle prefix as constant (#15918)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco authored Apr 29, 2024
1 parent cc7467f commit 1d4589b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore;
using OrchardCore.Autoroute;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Routing;

Expand All @@ -24,7 +25,7 @@ public static async Task<string> 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..];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,7 +81,7 @@ public async Task<IActionResult> 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<ItemGroup>
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Admin.Abstractions\OrchardCore.Admin.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Autoroute.Core\OrchardCore.Autoroute.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ContentPreview.Abstractions\OrchardCore.ContentPreview.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Data.Abstractions\OrchardCore.Data.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Deployment.Abstractions\OrchardCore.Deployment.Abstractions.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace OrchardCore.Autoroute;

public class AutorouteConstants
{
public const string SlugPrefix = "slug:";
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AutorouteHandleProvider : IContentHandleProvider

public async Task<string> GetContentItemIdAsync(string handle)
{
if (handle.StartsWith("slug:", StringComparison.OrdinalIgnoreCase))
if (handle.StartsWith(AutorouteConstants.SlugPrefix, StringComparison.OrdinalIgnoreCase))
{
handle = handle[5..];

Expand Down

0 comments on commit 1d4589b

Please sign in to comment.