0

I created a webform handler class extending from WebFormHandlerBase: The method, postsave has the following code:

public function postSave(WebformSubmissionInterface $webform_submission, $update = TRUE) {
    $account = \Drupal::currentUser();
    $user = \Drupal\user\Entity\User::load($account->id());
    $user->addRole('example');
    $user->save();
  }

A boolean and photo value are submitted by the webform submission. I need to submit the boolean and photo to account fields. How do I do it?

closed as unclear what you're asking by mradcliffe, Pierre.Vriens, sanzante, Free Radical, iStryker Feb 5 at 3:31

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • get the data from the webform_submission object and then save it to whatever properties? It may help you tremendously to rely on a IDE (such as phpstorm, netbeans, visual studio code) to inspect and debug code. – mradcliffe Jan 25 at 16:02
0

$account = \Drupal::currentUser(); $user = \Drupal\user\Entity\User::load($account->id()); $data = $webform_submission->getData(); $photo = $data['picture']; $user->set('field_photo', $photo); $user->save(); } The above code, for example, will take a webform element, key is 'picture' and set it to an account field, 'field_photo'.

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