Answers.Body: <p>Ben's answer sounds like a really good extra tool for this. Just for the record other solutions include</p>
  <ul>
  <li>using Tags and CMS User extension <a href="https://github.com/Skvare/com.skvare.cmsuser" rel="nofollow noreferrer">https://github.com/Skvare/com.skvare.cmsuser</a></li>
  <li>Drupal Rules eg <a href="https://github.com/eileenmcnaughton/civicrm_entity/pull/273/files" rel="nofollow noreferrer">https://github.com/eileenmcnaughton/civicrm_entity/pull/273/files</a></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-16T19:45:04.843Z
Answers.Text: Thanks for giving some alternative solutions :)
Answers.UserDisplayName: Ben
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-29T14:15:48.190Z
Answers.Text: So the workflow with the skvar extension is: Webform to create Contact with Group X or Tag Y --> chron to execute CMSUser --> CMSUser scans for Group-X or Tag-Y contacts and creates Drupal user then clears the X and Y so as to not repeat it.  Is that right?
Answers.UserDisplayName: HeneryH
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-10T18:36:37.503Z
Answers.LastActivityDate: 2021-02-10T18:36:37.503Z
Answers.UserDisplayName: petednz - fuzion
Answers.Body: <p>Using Webform and Webform CiviCRM modules create a webform with the fields required for the user and their organisation to create the contact and organisation in CiviCRM.</p>
  <p>Then create a WebformHandler to programmatically create the user using the postSave() function. The WebformHandler is a single php file that needs to be saved in a custom module folder as:
  <code>my_module/src/Plugin/WebformHandler/CreateUserHandler.php</code>
  I have created a basic guideline WebformHandler that creates the user and connects to the CiviContact at <a href="https://gist.github.com/bmango/0347f6c22b3fb38e34be57bb50f8e99e" rel="nofollow noreferrer">https://gist.github.com/bmango/0347f6c22b3fb38e34be57bb50f8e99e</a></p>
  <p>Note that the namespace declaration at the top of the script is not the same as the path to the file but will be:</p>
  <p><code>namespace Drupal\my_module\Plugin\WebformHandler;</code></p>
  <p>omitting the 'src'.</p>
  <p>Once you have created the WebformHandler it should appear on the Webform &quot;Email/Handlers&quot; tab where you can then add it to the form.</p>
  <p>This answer extends the <a href="https://drupal.stackexchange.com/a/245097/2369">answer</a> given by mAtZ to <a href="https://drupal.stackexchange.com/questions/243757/create-a-new-user-on-webform-submission">Create a new user on Webform submission</a>, by adding the code to connect the Drupal user account to the Civi contact.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-09T20:59:17.463Z
Answers.LastActivityDate: 2021-02-09T20:59:17.463Z
Answers.UserDisplayName: Ben
Body: <p>I have a need to use Webform (using the Webform CiviCRM module) in Drupal 8 to register a new user and their organisation in Civi and at the same time create the user account in Drupal and link it to the Civi contact. I can't use the standard Drupal register form as I want to include their organisation and other custom fields. How can I do this?</p>
  
Tags: <drupal><webform-civicrm><drupal-8>
Title: How to use webform to register a new user on Drupal 8/9 and link to contact in CiviCRM
ThreadText: # How to use webform to register a new user on Drupal 8/9 and link to contact in CiviCRM
  
  (Asked by: username_0 on 2021-02-09)
  
  I have a need to use Webform (using the Webform CiviCRM module) in Drupal 8 to register a new user and their organisation in Civi and at the same time create the user account in Drupal and link it to the Civi contact. I can't use the standard Drupal register form as I want to include their organisation and other custom fields. How can I do this?
  
  **Tags:** drupal, webform-civicrm, drupal-8
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-02-10. Score: 4
  
  username_0's answer sounds like a really good extra tool for this. Just for the record other solutions include
  
  * using Tags and CMS User extension <https://github.com/Skvare/com.skvare.cmsuser>
  * Drupal Rules eg <https://github.com/eileenmcnaughton/civicrm_entity/pull/273/files>
  
  > **Comments:**
  > **username_0**: Thanks for giving some alternative solutions :)  
  > **username_2**: So the workflow with the skvar extension is: Webform to create Contact with Group X or Tag Y --> chron to execute CMSUser --> CMSUser scans for Group-X or Tag-Y contacts and creates Drupal user then clears the X and Y so as to not repeat it.  Is that right?  
  
  ---
  
  ### Answer by username_0 on 2021-02-09. Score: 4
  
  Using Webform and Webform CiviCRM modules create a webform with the fields required for the user and their organisation to create the contact and organisation in CiviCRM.
  
  Then create a WebformHandler to programmatically create the user using the postSave() function. The WebformHandler is a single php file that needs to be saved in a custom module folder as:
  `my_module/src/Plugin/WebformHandler/CreateUserHandler.php`
  I have created a basic guideline WebformHandler that creates the user and connects to the CiviContact at <https://gist.github.com/bmango/0347f6c22b3fb38e34be57bb50f8e99e>
  
  Note that the namespace declaration at the top of the script is not the same as the path to the file but will be:
  
  `namespace Drupal\my_module\Plugin\WebformHandler;`
  
  omitting the 'src'.
  
  Once you have created the WebformHandler it should appear on the Webform "Email/Handlers" tab where you can then add it to the form.
  
  This answer extends the [answer](https://drupal.stackexchange.com/a/245097/2369) given by mAtZ to [Create a new user on Webform submission](https://drupal.stackexchange.com/questions/243757/create-a-new-user-on-webform-submission), by adding the code to connect the Drupal user account to the Civi contact.
  
  
  ---
  
  