From b6a4ef609df22723e6a509e6c410385a1ff684fa Mon Sep 17 00:00:00 2001 From: MarcoViglione-Laser Date: Thu, 25 Jul 2019 21:10:34 +0200 Subject: [PATCH] Use CreateRouteValues for creation routes (#8241) Fixes #8238 --- .../Views/Admin/CreatableTypeList.cshtml | 25 +++++++++++++++++-- .../Core/Contents/Views/Admin/List.cshtml | 25 +++++++++++++++---- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/Orchard.Web/Core/Contents/Views/Admin/CreatableTypeList.cshtml b/src/Orchard.Web/Core/Contents/Views/Admin/CreatableTypeList.cshtml index 28e908e00..3b6e187b1 100644 --- a/src/Orchard.Web/Core/Contents/Views/Admin/CreatableTypeList.cshtml +++ b/src/Orchard.Web/Core/Contents/Views/Admin/CreatableTypeList.cshtml @@ -1,5 +1,26 @@ -@{ Layout.Title = T("Create New Content").ToString(); } +@using Orchard; +@using Orchard.ContentManagement; +@using Orchard.Core.Contents; + +@{ + IOrchardServices _orchardServices; + WorkContext.TryResolve(out _orchardServices); + + Layout.Title = T("Create New Content"); +} @foreach (var type in Model.ContentTypes) { -

@Html.ActionLink((string)type.DisplayName, "Create", new { Area = "Contents", Id = (string)type.Name, ContainerId = Model.ContainerId, ReturnUrl = Request.QueryString["ReturnUrl"] })

+ var content = _orchardServices.ContentManager.New(type.Name); + + if (Authorizer.Authorize(Permissions.CreateContent, content)) { + ContentItemMetadata metadata = _orchardServices.ContentManager.GetItemMetadata(content); + + RouteValueDictionary createRouteValues = metadata.CreateRouteValues; + createRouteValues.Add("ContainerId", Model.ContainerId); + createRouteValues.Add("ReturnUrl", Request.QueryString["ReturnUrl"]); + + var url = Url.RouteUrl(createRouteValues); + +

@type.DisplayName

+ } } \ No newline at end of file diff --git a/src/Orchard.Web/Core/Contents/Views/Admin/List.cshtml b/src/Orchard.Web/Core/Contents/Views/Admin/List.cshtml index a2459180c..48d66e99a 100644 --- a/src/Orchard.Web/Core/Contents/Views/Admin/List.cshtml +++ b/src/Orchard.Web/Core/Contents/Views/Admin/List.cshtml @@ -1,13 +1,18 @@ -@using Orchard.Core.Contents; +@using Orchard; +@using Orchard.ContentManagement; +@using Orchard.Core.Contents; @using Orchard.Core.Contents.ViewModels; @using Orchard.Security; -@using Orchard.Security.Permissions; + @{ + IOrchardServices _orchardServices; + WorkContext.TryResolve(out _orchardServices); + var typeDisplayName = Model.TypeDisplayName; var pageTitle = T("Manage Content"); var createLinkText = T("Create New Content"); // if no specific type is selected, we assume we should show the "Create" button - var showCreateContentButton = string.IsNullOrWhiteSpace(typeDisplayName); + var showCreateContentButton = string.IsNullOrWhiteSpace(typeDisplayName); IAuthorizationService _authorizationService; WorkContext.TryResolve(out _authorizationService); @@ -26,9 +31,19 @@ Layout.Title = pageTitle.Text; } -@if (showCreateContentButton) { +@if (showCreateContentButton) {
- @Html.ActionLink(createLinkText.Text, "Create", new { Area = "Contents", Id = (string)Model.Options.SelectedFilter }, new { @class = "button primaryAction" }) + @{ + if (!String.IsNullOrWhiteSpace((string)Model.Options.SelectedFilter)) { + var content = _orchardServices.ContentManager.New(Model.Options.SelectedFilter); + ContentItemMetadata metadata = _orchardServices.ContentManager.GetItemMetadata(content); + + var url = Url.RouteUrl(metadata.CreateRouteValues); + @createLinkText.Text + } else { + @Html.ActionLink(createLinkText.Text, "Create", new { Area = "Contents", Id = (string)Model.Options.SelectedFilter }, new { @class = "button primaryAction" }); + } + }
} @using (Html.BeginFormAntiForgeryPost()) {