DynamicForms: Adding FormSubmission.FormName token

Contrib by Pablo Sanchez (https://github.com/psp589)
This commit is contained in:
Lombiq
2019-08-22 19:21:06 +02:00
committed by Benedek Farkas
parent 8c5d3b6fc7
commit 0279b1e79e

View File

@@ -10,7 +10,7 @@ namespace Orchard.DynamicForms.Tokens {
.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("CreatedContent", T("CreatedContent"), T("Id of the Content Item created by the form."))
;
.Token("FormName", T("FormName"), T("The name of the form posted."));
}
public void Evaluate(EvaluateContext context) {
@@ -19,7 +19,8 @@ namespace Orchard.DynamicForms.Tokens {
.Chain(FilterChainParam, "Text", GetFieldValue)
.Token(token => token.StartsWith("IsValid:", StringComparison.OrdinalIgnoreCase) ? token.Substring("IsValid:".Length) : null, GetFieldValidationStatus)
.Token("CreatedContent", GetCreatedContent)
.Chain("CreatedContent", "Content", GetCreatedContent);
.Chain("CreatedContent", "Content", GetCreatedContent)
.Token("FormName", GetFormName);
}
private static Tuple<string, string> FilterChainParam(string token) {
@@ -39,9 +40,12 @@ namespace Orchard.DynamicForms.Tokens {
return context.ModelState.IsValidField(fieldName);
}
private object GetCreatedContent(FormSubmissionTokenContext context)
{
private object GetCreatedContent(FormSubmissionTokenContext context) {
return context.CreatedContent;
}
private string GetFormName(FormSubmissionTokenContext context) {
return context.Form.Name;
}
}
}