Score:0

How do I get the submitter of a webform submission?

in flag

I'm developing my first webform handler and I need to access the submitter of the webform submission in the postSave method.

I know I can get the webform submission ID with $webform_submission->id(), but I can't figure out how to get the submitter. As far as I know, $webform_submission->getWebform()->getOwner() is NOT what I'm looking for, because it tells me the owner of the form, not the "owner" of the submission. I found How do I find out which what fields are available? but it's not as detailed as I need.

The reason why I need to know the submitter is the following:

  • I want to develop some kind of "wallet" for my website. For that purpose, I have installed the "profiles" module and I have created a "wallet" profile type with a single field: "Balance". So every user will have a "balance".

  • I have also created a webform called "New transaction" where users will submit deposits and/or withdrawals. This webform has, among other fields, a field "status" and a field "amount".

  • When a user submits a "new transaction", the webform submission gets stored with a status "VERIFYING" and an email handler sends an email to the administrator of the website (no WebformHandler is involved here).

  • The administrator receives the email and reviews the deposit/withdrawal. If it is OK, the administrator updates the status of the submission to "ACCEPTED". It is in that moment (when the administrator updates the submission) when the WebformHandler does its magic. It adds/substracts the amount to the balance of the wallet profile that belongs to the user that made the submission. This is why I need to know the user that created the webform submission. I need to do the following to retrieve the wallet profile of the user:

    $wallet_profiles = \Drupal::entityTypeManager()->getStorage("profile")
      ->loadByProperties(['uid' => $user->id(),
        'type' => 'wallet_profile',
        'is_default' => 1,
      ]);
    

If anyone knows of a more elegant way to achieve this "wallet" concept, please let me know.

Score:1
in flag

OK. I think I can answer myself: $webform_submission->getOwnerId() is what I need.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.