mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fixes #5563 : Allow token chaining on DynamicForms submissions.
This commit is contained in:
@@ -7,7 +7,7 @@ namespace Orchard.DynamicForms.Tokens {
|
||||
|
||||
public void Describe(DescribeContext context) {
|
||||
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."))
|
||||
.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."))
|
||||
;
|
||||
}
|
||||
@@ -15,10 +15,20 @@ namespace Orchard.DynamicForms.Tokens {
|
||||
public void Evaluate(EvaluateContext context) {
|
||||
context.For<FormSubmissionTokenContext>("FormSubmission")
|
||||
.Token(token => token.StartsWith("Field:", StringComparison.OrdinalIgnoreCase) ? token.Substring("Field:".Length) : null, GetFieldValue)
|
||||
.Chain(FilterChainParam, "Text", GetFieldValue)
|
||||
.Token(token => token.StartsWith("IsValid:", StringComparison.OrdinalIgnoreCase) ? token.Substring("IsValid:".Length) : null, GetFieldValidationStatus);
|
||||
}
|
||||
|
||||
private object GetFieldValue(string fieldName, FormSubmissionTokenContext context) {
|
||||
private static Tuple<string, string> FilterChainParam(string token) {
|
||||
int tokenLength = "Field:".Length;
|
||||
int chainIndex = token.IndexOf('.');
|
||||
if (token.StartsWith("Field:", StringComparison.OrdinalIgnoreCase) && chainIndex > tokenLength)
|
||||
return new Tuple<string, string>(token.Substring(tokenLength, chainIndex - tokenLength), token.Substring(chainIndex + 1));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
private string GetFieldValue(string fieldName, FormSubmissionTokenContext context) {
|
||||
return context.PostedValues[fieldName];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user