You are here

public static function BulkUserImport::batchImport in Bulk User Registration 8

Batch callback: User import operation.

Parameters

array $userData: Structured array of user data. The keys are user field names.

string $defaultRole: The default role.

array $context: Batch context data.

File

src/Form/BulkUserImport.php, line 217

Class

BulkUserImport
Bulk user import form.

Namespace

Drupal\bulk_user_registration\Form

Code

public static function batchImport(array $userData, $defaultRole, array &$context) {

  // Required user data is missing. Do not import.
  if (empty($userData[BulkUserRegistrationInterface::FIELD_EMAIL]) || empty($userData[BulkUserRegistrationInterface::FIELD_USER_NAME])) {
    return;
  }

  // This user already exists. Do not import.
  if (user_load_by_mail($userData[BulkUserRegistrationInterface::FIELD_EMAIL])) {
    return;
  }
  $user = \Drupal::service('bulk_user_registration')
    ->createUser($userData, $defaultRole);

  // Notify user via mail.
  if ($user
    ->isActive()) {
    _user_mail_notify('register_no_approval_required', $user);
  }
  $context['results'][] = $user
    ->id();
}