Рейтинг:0

How do I get the submitter of a webform submission?

флаг in

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.

Рейтинг:1
флаг in

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

Ответить или комментировать

Большинство людей не понимают, что склонность к познанию нового открывает путь к обучению и улучшает межличностные связи. В исследованиях Элисон, например, хотя люди могли точно вспомнить, сколько вопросов было задано в их разговорах, они не чувствовали интуитивно связи между вопросами и симпатиями. В четырех исследованиях, в которых участники сами участвовали в разговорах или читали стенограммы чужих разговоров, люди, как правило, не осознавали, что задаваемый вопрос повлияет — или повлиял — на уровень дружбы между собеседниками.