You are here

public static function ContentImport::getUserInfo in Content Import 8

Same name and namespace in other branches
  1. 8.3 src/Form/ContentImport.php \Drupal\contentimport\Form\ContentImport::getUserInfo()
  2. 8.4 src/Form/ContentImport.php \Drupal\contentimport\Form\ContentImport::getUserInfo()

To get user information based on emailIds

1 call to ContentImport::getUserInfo()
ContentImport::createNode in src/Form/ContentImport.php
To import data as Content type nodes.

File

src/Form/ContentImport.php, line 172
Contains \Drupal\contentimport\Form\ContentImport.

Class

ContentImport
Configure Content Import settings for this site.

Namespace

Drupal\contentimport\Form

Code

public static function getUserInfo($userArray) {
  $uids = [];
  foreach ($userArray as $usermail) {
    $users = \Drupal::entityTypeManager()
      ->getStorage('user')
      ->loadByProperties([
      'mail' => $usermail,
    ]);
    $user = reset($users);
    if ($user) {
      $uids[] = $user
        ->id();
    }
    else {
      $user = \Drupal\user\Entity\User::create();
      $user->uid = '';
      $user
        ->setUsername($usermail);
      $user
        ->setEmail($usermail);
      $user
        ->set("init", $usermail);
      $user
        ->enforceIsNew();
      $user
        ->activate();
      $user
        ->save();
      $users = \Drupal::entityTypeManager()
        ->getStorage('user')
        ->loadByProperties([
        'mail' => $usermail,
      ]);
      $uids[] = $user
        ->id();
    }
  }
  return $uids;
}