I am creating a "Stripe" submit handler that will perform a stripe charge. What I get from the post is just a token, and with that token I can do a number of things which could be configured in the submission handler.

I'd like to store additional information on the submission, not related to the form itself but that can be used/downloaded/retrieve later on.

Is there a way of doing this defining an own schema and doing a whole load of storing/loading manually?

I tried something like this on my handler:

  public function preSave(WebformSubmissionInterface $webform_submission) {
    $data = $webform_submission->getData();
    $data['extra'] = 'something';
    $webform_submission->setData($data);
  }

which makes webform store the extra information, however, it's doesn't get shown on view/table/yamlexport because it's not an "element" of the webform. I haven't yet found alterers for those although maybe the view is just the entity view.

Any recommendations/suggestions around this could work.

Two other things I thought of, which I don't like are:
- creating a composite field with a bunch of value fields to store this optional data
- creating a value field on the form and add a setting to the submit handler to select a value field from the form to store this data.

Comments

hanoii created an issue. See original summary.

jrockowitz’s picture

Composite with hidden values makes the most sense to me.

jrockowitz’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

kenorb’s picture

ssawyersj’s picture

Perhaps I am missing something here, but custom composite doesn't seem to have "hidden" available as an element type. (You can manually set '#type':hidden in the YAML, but then you can't use the UI to change anything else about the composite.)

Or did you just mean put normal element fields in a custom composite and then hide the whole composite? (Presumably while also leaving "Clear value(s) when hidden" unchecked, or else that functionality is going to step on the attempt to use the composite to store data.)