3

I'm working on a custom field type for WFFM forms that records a cookie. Our save action uses the ControlResult's FieldType property to know when it's a field of this type and do some extra logic on it. The property is added during the control's GetResult method, which looks like this:

public override ControlResult GetResult()
{
    ControlResult result = new ControlResult(this.FieldItemId, this.Name, (object) this.Value, this.ResultParameters, false)
    {
        FieldType = FieldType
    };

    return result;
}

We have a custom save action (CustomSendEmail, which implements ISaveAction) that reads the control results as an AdaptedResultList in its Execute method:

public void Execute(ID formId, AdaptedResultList adaptedFields, ActionCallContext actionCallContext = null, params object[] data)

When I try to debug I observe two things:

  1. My custom GetResult methods runs as expected, and I can observe the FieldType property set on the result before it returns.
  2. By the beginning of the Execute method, the control result still exists but the FieldType is now null.

What step am I missing for my FieldType to survive into the save action?

Relevant details:

  • Sitecore 8.1 update 3
  • WFFM version consistent with Sitecore version
  • Glass Mapper and Castle Windsor (although I don't think they affect anything here)
0

Ah, I think I may have figured this out. The ControlResult get passed in to an AdaptedControlResult before making it to the Execute method's AdaptedControlList parameter. The constructor for AdaptedControlResult sets all of the parameters except FieldType, which it ignores:

public AdaptedControlResult(ControlResult result, IFieldProvider fieldProvider, bool simpleAdapt = false)
{
    Assert.ArgumentNotNull((object) result, "result");
    Assert.ArgumentNotNull((object) fieldProvider, "fieldProvider");
    this.FieldName = result.FieldName;
    this.Parameters = result.Parameters;
    this.FieldID = result.FieldID;
    this.Secure = result.Secure;
    ID result1;
    if (!ID.TryParse(result.FieldID, out result1))
    result1 = ID.Null;
    this.Value = simpleAdapt ? (result.Value ?? (object) string.Empty).ToString() : fieldProvider.GetAdaptedResult(result1, result.Value);
}

So there's no way to have that persist. Guess I'll have to use Parameters instead.

  • Mike, it's ok to post answer to your own question. But its a good practice to also accept the answer if that resolve the problem you were facing. :-) – Amitabh Vyas Nov 16 '18 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.