-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed9448a
commit 95b3301
Showing
75 changed files
with
2,401 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutorouteContentHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Routing; | ||
using OrchardCore.ContentManagement; | ||
using OrchardCore.ContentManagement.Handlers; | ||
using OrchardCore.ContentManagement.Routing; | ||
|
||
namespace OrchardCore.Autoroute.Handlers | ||
{ | ||
public class AutorouteContentHandler : ContentHandlerBase | ||
{ | ||
private readonly IAutorouteEntries _autorouteEntries; | ||
|
||
public AutorouteContentHandler(IAutorouteEntries autorouteEntries) | ||
{ | ||
_autorouteEntries = autorouteEntries; | ||
} | ||
|
||
public override Task GetContentItemAspectAsync(ContentItemAspectContext context) | ||
{ | ||
return context.ForAsync<ContentItemMetadata>(metadata => | ||
{ | ||
// When a content item is contained we provide different route values when generating urls. | ||
if (_autorouteEntries.TryGetEntryByContentItemId(context.ContentItem.ContentItemId, out var entry) && | ||
!string.IsNullOrEmpty(entry.ContainedContentItemId)) | ||
{ | ||
metadata.DisplayRouteValues = new RouteValueDictionary { | ||
{ "Area", "OrchardCore.Contents" }, | ||
{ "Controller", "Item" }, | ||
{ "Action", "Display" }, | ||
{ "ContentItemId", entry.ContentItemId}, | ||
{ "ContainedContentItemId", entry.ContainedContentItemId } | ||
}; | ||
} | ||
|
||
return Task.CompletedTask; | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.