Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoroute handle prefix as constant #15918

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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