Different registration procedures (with or without approval) for different roles? I am currently setting up a simple LMS in D8 and would like to create different registration procedures for different kinds of users. In particular:


There should be a registration page for simple member profiles: Only basic user data should be required and the account should be unlocked immediately after registration (and e-mail confirmation).
There should be a second registration page for student profiles: They need to upload a valid student identity card, which is why their registration requires admin approval.


I have already set up different registration profiles/pages for members and students and after registration the correct role is automatically assigned to the new user. So, that is working well already.

However, I need to also set up a different approval process, depending on the registered role and I'm not sure, how to approach this. Note: I really don't want this to be a two-step process, where students register as members first and only then upload the required documents. I need to make this as easy and quick as possible for them, while at the same time allowing for unrestricted member registrations.

Note that I'm working in D8 and I'm hesitant to install the Rules module, as there doesn't seem to be a stable version yet. Or is it usable?

Can this be done? Any help?
So, first of all, I'd like to refer to my other answer here, it's good to take a look

You are going to be needing to separate webforms, each with its own required fields, then after building our webform, in Emails \ Handlers section located at admin/structure/webform/manage/[WebformName]/handlers. We are going to enable our custom webform handler module.


  One thing that you need to make sure is correct, is the structure of
  the module folder, so that webform would read it as a handler, we
  assume the module name here is: webform_handler_user_creation so the
  structure would be something like this:
  webform_handler_user_creation&gt;src&gt;Plugin&gt;WebformHandler&gt;UserCreationHandler.php
  with a webform_handler_user_creation.info.yml file in the root of
  the module directory.


With all that said, here's an example of the module on my github page

So what we need to do first is to make sure we do create our users after saving the webform submission, then load the submission values and use them based on their machine names to fill in our user creation thingy, here's an example code:

&lt;?php
namespace Drupal\webform_handler_user_creation\Plugin\WebformHandler;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Plugin\WebformHandlerBase;
use Drupal\webform\WebformSubmissionInterface;
use Drupal\webform\Entity\WebformSubmission;
/**
 * Webform submission action handler.
 *
 * @WebformHandler(
 *   id = "usercreate",
 *   label = @Translation("User Create"),
 *   category = @Translation("Action"),
 *   description = @Translation("Creates a user after submission"),
 *   cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_UNLIMITED,
 *   results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
 *   submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_OPTIONAL,
 * )
 */
class UserCreationHandler extends WebformHandlerBase {
  /**
   * {@inheritdoc}
   */
  public function postSave(WebformSubmissionInterface $webform_submission, $update = TRUE) {
        $user = \Drupal\user\Entity\User::create();
        $language = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getId();
        $user_name = $webform_submission-&gt;getElementData('user_name');
        // Mandatory user creation settings
        $user-&gt;enforceIsNew();
        $user-&gt;setPassword('testPassword');
        $user-&gt;setEmail('test@example.com');
        $user-&gt;setUsername($user_name); // This username must be unique and accept only a-Z,0-9, - _ @ .
        $user-&gt;set("langcode", $language);
        // Optional settings
        $user-&gt;set("init", 'email');
        $user-&gt;set("preferred_langcode", $language);
        $user-&gt;set("preferred_admin_langcode", $language);
        $user-&gt;activate();
        // Add a custom role
        $user-&gt;addRole('CustomRoleName');
        //Save user
        $user-&gt;save();

  }
}


So based on your use case, you can add the user with a custom role with $user-&gt;addRole('CustomRoleName'); and maybe activate it with $user-&gt;activate(); it or a lot other things. You will be needing two different handlers/module with different concept for each role, one for simple member profiles and one for student profiles