mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-16 01:26:57 +08:00
Added checks to properly display CustomForm content items at front end (#8751)
* Display CustomForm_Wrapper shape only if shape type is Detail. Publish button has to be visible only if content is draftable AND is set to show the publish button # Conflicts: # src/Orchard.Web/Modules/Orchard.CustomForms/Drivers/CustomFormPartDriver.cs # src/Orchard.Web/Modules/Orchard.CustomForms/Views/Item/Create.cshtml # src/Orchard.Web/Modules/Orchard.CustomForms/Views/Parts.CustomForm.Wrapper.cshtml * Added EditorBuilderWrapper.
This commit is contained in:
parent
4043df7a0d
commit
417af34b4e
@ -11,20 +11,26 @@ using System;
|
|||||||
using Orchard.Core.Contents.Settings;
|
using Orchard.Core.Contents.Settings;
|
||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
|
using Orchard.CustomForms.Services;
|
||||||
|
|
||||||
namespace Orchard.CustomForms.Drivers {
|
namespace Orchard.CustomForms.Drivers {
|
||||||
public class CustomFormPartDriver : ContentPartDriver<CustomFormPart> {
|
public class CustomFormPartDriver : ContentPartDriver<CustomFormPart> {
|
||||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
private readonly IOrchardServices _orchardServices;
|
private readonly IOrchardServices _orchardServices;
|
||||||
private readonly IAuthorizationService _authService;
|
private readonly IAuthorizationService _authService;
|
||||||
|
private readonly IEditorBuilderWrapper _editorBuilderWrapper;
|
||||||
|
|
||||||
public CustomFormPartDriver(
|
public CustomFormPartDriver(
|
||||||
IContentDefinitionManager contentDefinitionManager,
|
IContentDefinitionManager contentDefinitionManager,
|
||||||
IOrchardServices orchardServices,
|
IOrchardServices orchardServices,
|
||||||
IAuthorizationService authService) {
|
IAuthorizationService authService,
|
||||||
|
IEditorBuilderWrapper editorBuilderWrapper) {
|
||||||
|
|
||||||
_contentDefinitionManager = contentDefinitionManager;
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
_orchardServices = orchardServices;
|
_orchardServices = orchardServices;
|
||||||
_authService = authService;
|
_authService = authService;
|
||||||
|
_editorBuilderWrapper = editorBuilderWrapper;
|
||||||
|
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,39 +38,43 @@ namespace Orchard.CustomForms.Drivers {
|
|||||||
|
|
||||||
protected override DriverResult Display(CustomFormPart part, string displayType, dynamic shapeHelper) {
|
protected override DriverResult Display(CustomFormPart part, string displayType, dynamic shapeHelper) {
|
||||||
// this method is used by the widget to render the form when it is displayed
|
// this method is used by the widget to render the form when it is displayed
|
||||||
|
// Display CustomForm_Wrapper shape only if shape type is Detail.
|
||||||
|
if (displayType.Equals("Detail")) {
|
||||||
|
int contentId = 0;
|
||||||
|
var queryString = _orchardServices.WorkContext.HttpContext.Request.QueryString;
|
||||||
|
|
||||||
int contentId = 0;
|
if (queryString.AllKeys.Contains("contentId")) {
|
||||||
var queryString = _orchardServices.WorkContext.HttpContext.Request.QueryString;
|
int.TryParse(queryString["contentId"], out contentId);
|
||||||
|
}
|
||||||
|
|
||||||
if (queryString.AllKeys.Contains("contentId")) {
|
ContentItem contentItem;
|
||||||
int.TryParse(queryString["contentId"], out contentId);
|
if (contentId > 0) {
|
||||||
}
|
contentItem = _orchardServices.ContentManager.Get(contentId);
|
||||||
|
|
||||||
ContentItem contentItem;
|
if (part.UseContentTypePermissions && !_orchardServices.Authorizer.Authorize(Core.Contents.Permissions.EditContent, contentItem))
|
||||||
if (contentId > 0) {
|
return null;
|
||||||
contentItem = _orchardServices.ContentManager.Get(contentId);
|
} else {
|
||||||
|
contentItem = _orchardServices.ContentManager.New(part.ContentType);
|
||||||
|
|
||||||
if (part.UseContentTypePermissions && !_orchardServices.Authorizer.Authorize(Core.Contents.Permissions.EditContent, contentItem))
|
if (part.UseContentTypePermissions && !_orchardServices.Authorizer.Authorize(Core.Contents.Permissions.CreateContent, contentItem))
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contentItem == null || contentItem.ContentType != part.ContentType)
|
||||||
return null;
|
return null;
|
||||||
} else {
|
|
||||||
contentItem = _orchardServices.ContentManager.New(part.ContentType);
|
|
||||||
|
|
||||||
if (part.UseContentTypePermissions && !_orchardServices.Authorizer.Authorize(Core.Contents.Permissions.CreateContent, contentItem))
|
if (!contentItem.Has<ICommonPart>()) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ContentShape("Parts_CustomForm_Wrapper", () => {
|
||||||
|
return shapeHelper.Parts_CustomForm_Wrapper()
|
||||||
|
.Editor(_editorBuilderWrapper.BuildEditor(contentItem))
|
||||||
|
.ContentPart(part);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
// Returning null avoids rendering the edit shape for current custom form.
|
||||||
if (contentItem == null || contentItem.ContentType != part.ContentType)
|
return null;
|
||||||
return null;
|
|
||||||
|
|
||||||
if (!contentItem.Has<ICommonPart>()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ContentShape("Parts_CustomForm_Wrapper", () => {
|
|
||||||
return shapeHelper.Parts_CustomForm_Wrapper()
|
|
||||||
.Editor(_orchardServices.ContentManager.BuildEditor(contentItem))
|
|
||||||
.ContentPart(part);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DriverResult Editor(CustomFormPart part, dynamic shapeHelper) {
|
protected override DriverResult Editor(CustomFormPart part, dynamic shapeHelper) {
|
||||||
|
@ -146,6 +146,8 @@
|
|||||||
<Compile Include="Rules\CustomFormEvents.cs" />
|
<Compile Include="Rules\CustomFormEvents.cs" />
|
||||||
<Compile Include="Rules\IRulesManager.cs" />
|
<Compile Include="Rules\IRulesManager.cs" />
|
||||||
<Compile Include="Security\AuthorizationEventHandler.cs" />
|
<Compile Include="Security\AuthorizationEventHandler.cs" />
|
||||||
|
<Compile Include="Services\EditorBuilderWrapper.cs" />
|
||||||
|
<Compile Include="Services\IEditorBuilderWrapper.cs" />
|
||||||
<Compile Include="ViewModels\CustomFormIndexViewModel.cs" />
|
<Compile Include="ViewModels\CustomFormIndexViewModel.cs" />
|
||||||
<Compile Include="ViewModels\CustomFormPartEditViewModel.cs" />
|
<Compile Include="ViewModels\CustomFormPartEditViewModel.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -231,4 +233,4 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Error Condition="!Exists('..\..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
|
<Error Condition="!Exists('..\..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
@ -0,0 +1,22 @@
|
|||||||
|
using Orchard.ContentManagement;
|
||||||
|
|
||||||
|
namespace Orchard.CustomForms.Services {
|
||||||
|
public class EditorBuilderWrapper : IEditorBuilderWrapper {
|
||||||
|
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
|
public EditorBuilderWrapper(
|
||||||
|
IContentManager contentManager) {
|
||||||
|
|
||||||
|
_contentManager = contentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public dynamic BuildEditor(IContent content) {
|
||||||
|
return _contentManager.BuildEditor(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public dynamic UpdateEditor(IContent content, IUpdateModel updateModel) {
|
||||||
|
return _contentManager.UpdateEditor(content, updateModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
using Orchard.ContentManagement;
|
||||||
|
|
||||||
|
namespace Orchard.CustomForms.Services {
|
||||||
|
public interface IEditorBuilderWrapper : IDependency {
|
||||||
|
dynamic BuildEditor(IContent content);
|
||||||
|
dynamic UpdateEditor(IContent content, IUpdateModel updateModel);
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,13 @@
|
|||||||
@using Orchard.ContentManagement
|
@using Orchard.ContentManagement
|
||||||
@using Orchard.Utility.Extensions
|
@using Orchard.Utility.Extensions
|
||||||
@using Orchard.ContentManagement.Aspects;
|
@using Orchard.ContentManagement.Aspects;
|
||||||
|
@using Orchard.ContentManagement.MetaData;
|
||||||
|
@using Orchard.ContentManagement.MetaData.Models;
|
||||||
|
@using Orchard.Core.Contents.Settings;
|
||||||
|
|
||||||
@{
|
@{
|
||||||
|
IContentDefinitionManager _contentDefinitionManager = WorkContext.Resolve<IContentDefinitionManager>();
|
||||||
|
|
||||||
ContentItem customForm = Model.ContentItem;
|
ContentItem customForm = Model.ContentItem;
|
||||||
string returnUrl = Model.ReturnUrl;
|
string returnUrl = Model.ReturnUrl;
|
||||||
var metadata = customForm.ContentManager.GetItemMetadata(customForm);
|
var metadata = customForm.ContentManager.GetItemMetadata(customForm);
|
||||||
@ -14,6 +20,18 @@
|
|||||||
|
|
||||||
var submitButtonText = String.IsNullOrEmpty(Model.ContentItem.CustomFormPart.SubmitButtonText) ? T("Submit").Text : Model.ContentItem.CustomFormPart.SubmitButtonText;
|
var submitButtonText = String.IsNullOrEmpty(Model.ContentItem.CustomFormPart.SubmitButtonText) ? T("Submit").Text : Model.ContentItem.CustomFormPart.SubmitButtonText;
|
||||||
var publishButtonText = String.IsNullOrEmpty(Model.ContentItem.CustomFormPart.PublishButtonText) ? T("Publish").Text : Model.ContentItem.CustomFormPart.PublishButtonText;
|
var publishButtonText = String.IsNullOrEmpty(Model.ContentItem.CustomFormPart.PublishButtonText) ? T("Publish").Text : Model.ContentItem.CustomFormPart.PublishButtonText;
|
||||||
|
|
||||||
|
var showPublishButton = Model.ContentItem.CustomFormPart.SavePublishContentItem;
|
||||||
|
// Read type definition to check if content is draftable
|
||||||
|
var typeDefinition = _contentDefinitionManager
|
||||||
|
.ListTypeDefinitions()
|
||||||
|
.Where(x => String.Equals(x.Name, Model.ContentItem.CustomFormPart.ContentType, StringComparison.OrdinalIgnoreCase))
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (typeDefinition != null) {
|
||||||
|
// Publish button has to be visible only if content is draftable AND is set to show the publish button
|
||||||
|
showPublishButton = showPublishButton &&
|
||||||
|
typeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Display(New.Parts_Title().Title(displayText))
|
@Display(New.Parts_Title().Title(displayText))
|
||||||
@ -29,8 +47,22 @@
|
|||||||
@if (Model.ContentItem.CustomFormPart.SavePublishContentItem == false || Model.ContentItem.CustomFormPart.SaveContentItem == true) {
|
@if (Model.ContentItem.CustomFormPart.SavePublishContentItem == false || Model.ContentItem.CustomFormPart.SaveContentItem == true) {
|
||||||
<button type="submit" name="submit.Save" value="submit.Save">@submitButtonText</button>
|
<button type="submit" name="submit.Save" value="submit.Save">@submitButtonText</button>
|
||||||
}
|
}
|
||||||
@if (Model.ContentItem.CustomFormPart.SavePublishContentItem == true) {
|
@if (showPublishButton) {
|
||||||
<button type="submit" name="submit.Publish" value="submit.Publish">@publishButtonText</button>
|
<button type="submit" name="submit.Publish" value="submit.Publish">@publishButtonText</button>
|
||||||
}
|
}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="edit-item-secondary group">
|
||||||
|
@if (Model.Actions != null) {
|
||||||
|
<div class="edit-item-actions">
|
||||||
|
@Display(Model.Actions)
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
@if (Model.Sidebar != null) {
|
||||||
|
<div class="edit-item-sidebar group">
|
||||||
|
@Display(Model.Sidebar)
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
}
|
}
|
@ -1,4 +1,10 @@
|
|||||||
@{
|
@using Orchard.ContentManagement.MetaData;
|
||||||
|
@using Orchard.ContentManagement.MetaData.Models;
|
||||||
|
@using Orchard.Core.Contents.Settings;
|
||||||
|
|
||||||
|
@{
|
||||||
|
IContentDefinitionManager _contentDefinitionManager = WorkContext.Resolve<IContentDefinitionManager>();
|
||||||
|
|
||||||
dynamic editor = Model.Editor;
|
dynamic editor = Model.Editor;
|
||||||
|
|
||||||
if (TempData.ContainsKey("CustomFormWidget.InvalidCustomFormState")) {
|
if (TempData.ContainsKey("CustomFormWidget.InvalidCustomFormState")) {
|
||||||
@ -7,18 +13,34 @@
|
|||||||
|
|
||||||
// remove default Save/Publish buttons
|
// remove default Save/Publish buttons
|
||||||
editor.Zones["Sidebar"].Items.Clear();
|
editor.Zones["Sidebar"].Items.Clear();
|
||||||
|
|
||||||
|
var showPublishButton = Model.ContentItem.CustomFormPart.SavePublishContentItem;
|
||||||
|
|
||||||
|
// Read type definition to check if content is draftable
|
||||||
|
var typeDefinition = _contentDefinitionManager
|
||||||
|
.ListTypeDefinitions()
|
||||||
|
.Where(x => String.Equals(x.Name, Model.ContentItem.CustomFormPart.ContentType, StringComparison.OrdinalIgnoreCase))
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (typeDefinition != null) {
|
||||||
|
// Publish button has to be visible only if content is draftable AND is set to show the publish button
|
||||||
|
showPublishButton = showPublishButton &&
|
||||||
|
typeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@using (Html.BeginFormAntiForgeryPost(Url.Action("Create", "Item", new { area = "Orchard.CustomForms", id = Model.ContentItem.Id }))) {
|
@using (Html.BeginFormAntiForgeryPost(Url.Action("Create", "Item", new { area = "Orchard.CustomForms", id = Model.ContentItem.Id }))) {
|
||||||
@Html.ValidationSummary()
|
@Html.ValidationSummary()
|
||||||
// Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type
|
// Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type
|
||||||
@Display(editor)
|
@Display(editor)
|
||||||
@Html.Hidden("returnUrl", Request.RawUrl, new { id = string.Empty });
|
|
||||||
@Html.Hidden("contentId", !string.IsNullOrWhiteSpace(Request.QueryString["contentId"]) ? Request.QueryString["contentId"] : "0", new { id = string.Empty });
|
@Html.Hidden("returnUrl", Request.RawUrl, new { id = string.Empty });
|
||||||
<fieldset class="submit-button">
|
@Html.Hidden("contentId", !string.IsNullOrWhiteSpace(Request.QueryString["contentId"]) ? Request.QueryString["contentId"] : "0", new { id = string.Empty });
|
||||||
<button type="submit" name="submit.Save" value="submit.Save">@Model.ContentPart.SubmitButtonText</button>
|
|
||||||
@if (Model.ContentItem.CustomFormPart.SavePublishContentItem == true) {
|
<fieldset class="submit-button">
|
||||||
<button type="submit" name="submit.Publish" value="submit.Publish">@Model.ContentPart.PublishButtonText</button>
|
|
||||||
}
|
<button type="submit" name="submit.Save" value="submit.Save">@Model.ContentPart.SubmitButtonText</button>
|
||||||
</fieldset>
|
@if (showPublishButton) {
|
||||||
}
|
<button type="submit" name="submit.Publish" value="submit.Publish">@Model.ContentPart.PublishButtonText</button>
|
||||||
|
}
|
||||||
|
</fieldset>
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user