|
11 | 11 | using Orchard.Core.Contents.Settings;
|
12 | 12 | using Orchard.Security;
|
13 | 13 | using Orchard.Localization;
|
| 14 | +using Orchard.CustomForms.Services; |
14 | 15 |
|
15 | 16 | namespace Orchard.CustomForms.Drivers {
|
16 | 17 | public class CustomFormPartDriver : ContentPartDriver<CustomFormPart> {
|
17 | 18 | private readonly IContentDefinitionManager _contentDefinitionManager;
|
18 | 19 | private readonly IOrchardServices _orchardServices;
|
19 | 20 | private readonly IAuthorizationService _authService;
|
| 21 | + private readonly IEditorBuilderWrapper _editorBuilderWrapper; |
20 | 22 |
|
21 | 23 | public CustomFormPartDriver(
|
22 | 24 | IContentDefinitionManager contentDefinitionManager,
|
23 | 25 | IOrchardServices orchardServices,
|
24 |
| - IAuthorizationService authService) { |
| 26 | + IAuthorizationService authService, |
| 27 | + IEditorBuilderWrapper editorBuilderWrapper) { |
| 28 | + |
25 | 29 | _contentDefinitionManager = contentDefinitionManager;
|
26 | 30 | _orchardServices = orchardServices;
|
27 | 31 | _authService = authService;
|
| 32 | + _editorBuilderWrapper = editorBuilderWrapper; |
| 33 | + |
28 | 34 | T = NullLocalizer.Instance;
|
29 | 35 | }
|
30 | 36 |
|
31 | 37 | public Localizer T { get; set; }
|
32 | 38 |
|
33 | 39 | protected override DriverResult Display(CustomFormPart part, string displayType, dynamic shapeHelper) {
|
34 | 40 | // this method is used by the widget to render the form when it is displayed
|
| 41 | + // Display CustomForm_Wrapper shape only if shape type is Detail. |
| 42 | + if (displayType.Equals("Detail")) { |
| 43 | + int contentId = 0; |
| 44 | + var queryString = _orchardServices.WorkContext.HttpContext.Request.QueryString; |
35 | 45 |
|
36 |
| - int contentId = 0; |
37 |
| - var queryString = _orchardServices.WorkContext.HttpContext.Request.QueryString; |
| 46 | + if (queryString.AllKeys.Contains("contentId")) { |
| 47 | + int.TryParse(queryString["contentId"], out contentId); |
| 48 | + } |
38 | 49 |
|
39 |
| - if (queryString.AllKeys.Contains("contentId")) { |
40 |
| - int.TryParse(queryString["contentId"], out contentId); |
41 |
| - } |
| 50 | + ContentItem contentItem; |
| 51 | + if (contentId > 0) { |
| 52 | + contentItem = _orchardServices.ContentManager.Get(contentId); |
42 | 53 |
|
43 |
| - ContentItem contentItem; |
44 |
| - if (contentId > 0) { |
45 |
| - contentItem = _orchardServices.ContentManager.Get(contentId); |
| 54 | + if (part.UseContentTypePermissions && !_orchardServices.Authorizer.Authorize(Core.Contents.Permissions.EditContent, contentItem)) |
| 55 | + return null; |
| 56 | + } else { |
| 57 | + contentItem = _orchardServices.ContentManager.New(part.ContentType); |
46 | 58 |
|
47 |
| - if (part.UseContentTypePermissions && !_orchardServices.Authorizer.Authorize(Core.Contents.Permissions.EditContent, contentItem)) |
48 |
| - return null; |
49 |
| - } else { |
50 |
| - contentItem = _orchardServices.ContentManager.New(part.ContentType); |
| 59 | + if (part.UseContentTypePermissions && !_orchardServices.Authorizer.Authorize(Core.Contents.Permissions.CreateContent, contentItem)) |
| 60 | + return null; |
| 61 | + } |
51 | 62 |
|
52 |
| - if (part.UseContentTypePermissions && !_orchardServices.Authorizer.Authorize(Core.Contents.Permissions.CreateContent, contentItem)) |
| 63 | + if (contentItem == null || contentItem.ContentType != part.ContentType) |
53 | 64 | return null;
|
54 |
| - } |
55 | 65 |
|
56 |
| - if (contentItem == null || contentItem.ContentType != part.ContentType) |
57 |
| - return null; |
| 66 | + if (!contentItem.Has<ICommonPart>()) { |
| 67 | + return null; |
| 68 | + } |
58 | 69 |
|
59 |
| - if (!contentItem.Has<ICommonPart>()) { |
60 |
| - return null; |
| 70 | + return ContentShape("Parts_CustomForm_Wrapper", () => { |
| 71 | + return shapeHelper.Parts_CustomForm_Wrapper() |
| 72 | + .Editor(_editorBuilderWrapper.BuildEditor(contentItem)) |
| 73 | + .ContentPart(part); |
| 74 | + }); |
61 | 75 | }
|
62 |
| - |
63 |
| - return ContentShape("Parts_CustomForm_Wrapper", () => { |
64 |
| - return shapeHelper.Parts_CustomForm_Wrapper() |
65 |
| - .Editor(_orchardServices.ContentManager.BuildEditor(contentItem)) |
66 |
| - .ContentPart(part); |
67 |
| - }); |
| 76 | + // Returning null avoids rendering the edit shape for current custom form. |
| 77 | + return null; |
68 | 78 | }
|
69 | 79 |
|
70 | 80 | protected override DriverResult Editor(CustomFormPart part, dynamic shapeHelper) {
|
|
0 commit comments