Adds Created Content token for Dynamic Form submission (#7879)

Fixes #7878
This commit is contained in:
ub3rman123 2017-11-09 15:06:08 -05:00 committed by Sébastien Ros
parent 2904d35d91
commit 59dc2bab85
3 changed files with 15 additions and 4 deletions

View File

@ -50,6 +50,7 @@ namespace Orchard.DynamicForms.Handlers {
var contentItem = default(ContentItem); var contentItem = default(ContentItem);
if (form.CreateContent == true && !String.IsNullOrWhiteSpace(form.FormBindingContentType)) { if (form.CreateContent == true && !String.IsNullOrWhiteSpace(form.FormBindingContentType)) {
contentItem = formService.CreateContentItem(form, context.ValueProvider); contentItem = formService.CreateContentItem(form, context.ValueProvider);
formTokenContext.CreatedContent = contentItem;
} }
// Notifiy. // Notifiy.
@ -60,4 +61,4 @@ namespace Orchard.DynamicForms.Handlers {
_workflowManager.TriggerEvent(DynamicFormSubmittedActivity.EventName, contentItem, () => tokenData); _workflowManager.TriggerEvent(DynamicFormSubmittedActivity.EventName, contentItem, () => tokenData);
} }
} }
} }

View File

@ -1,11 +1,13 @@
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.DynamicForms.Elements; using Orchard.DynamicForms.Elements;
using Orchard.ContentManagement;
namespace Orchard.DynamicForms.Services.Models { namespace Orchard.DynamicForms.Services.Models {
public class FormSubmissionTokenContext { public class FormSubmissionTokenContext {
public Form Form { get; set; } public Form Form { get; set; }
public ModelStateDictionary ModelState { get; set; } public ModelStateDictionary ModelState { get; set; }
public NameValueCollection PostedValues { get; set; } public NameValueCollection PostedValues { get; set; }
public ContentItem CreatedContent { get; set; }
} }
} }

View File

@ -9,6 +9,7 @@ namespace Orchard.DynamicForms.Tokens {
context.For("FormSubmission", T("Dynamic Form submission"), T("Dynamic Form Submission tokens for use in workflows handling the Dynamic Form Submitted event.")) context.For("FormSubmission", T("Dynamic Form submission"), T("Dynamic Form Submission tokens for use in workflows handling the Dynamic Form Submitted event."))
.Token("Field:*", T("Field:<field name>"), T("The posted field value to access."), "Text") .Token("Field:*", T("Field:<field name>"), T("The posted field value to access."), "Text")
.Token("IsValid:*", T("IsValid:<field name>"), T("The posted field validation status.")) .Token("IsValid:*", T("IsValid:<field name>"), T("The posted field validation status."))
.Token("CreatedContent", T("CreatedContent"), T("Id of the Content Item created by the form."))
; ;
} }
@ -16,7 +17,9 @@ namespace Orchard.DynamicForms.Tokens {
context.For<FormSubmissionTokenContext>("FormSubmission") context.For<FormSubmissionTokenContext>("FormSubmission")
.Token(token => token.StartsWith("Field:", StringComparison.OrdinalIgnoreCase) ? token.Substring("Field:".Length) : null, GetFieldValue) .Token(token => token.StartsWith("Field:", StringComparison.OrdinalIgnoreCase) ? token.Substring("Field:".Length) : null, GetFieldValue)
.Chain(FilterChainParam, "Text", GetFieldValue) .Chain(FilterChainParam, "Text", GetFieldValue)
.Token(token => token.StartsWith("IsValid:", StringComparison.OrdinalIgnoreCase) ? token.Substring("IsValid:".Length) : null, GetFieldValidationStatus); .Token(token => token.StartsWith("IsValid:", StringComparison.OrdinalIgnoreCase) ? token.Substring("IsValid:".Length) : null, GetFieldValidationStatus)
.Token("CreatedContent", GetCreatedContent)
.Chain("CreatedContent", "Content", GetCreatedContent);
} }
private static Tuple<string, string> FilterChainParam(string token) { private static Tuple<string, string> FilterChainParam(string token) {
@ -35,5 +38,10 @@ namespace Orchard.DynamicForms.Tokens {
private object GetFieldValidationStatus(string fieldName, FormSubmissionTokenContext context) { private object GetFieldValidationStatus(string fieldName, FormSubmissionTokenContext context) {
return context.ModelState.IsValidField(fieldName); return context.ModelState.IsValidField(fieldName);
} }
private object GetCreatedContent(FormSubmissionTokenContext context)
{
return context.CreatedContent;
}
} }
} }