You are here

private function UserCsvImportController::createUser in User CSV import 8

Same name and namespace in other branches
  1. 2.0.x src/Controller/UserCsvImportController.php \Drupal\user_csv_import\Controller\UserCsvImportController::createUser()
  2. 1.0.x src/Controller/UserCsvImportController.php \Drupal\user_csv_import\Controller\UserCsvImportController::createUser()

Creates a new user from prepared values.

Parameters

array $values: Values prepared from prepareRow().

Return value

\Drupal\user\Entity\User

1 call to UserCsvImportController::createUser()
UserCsvImportController::processUpload in src/Controller/UserCsvImportController.php
Processes an uploaded CSV file, creating a new user for each row of values.

File

src/Controller/UserCsvImportController.php, line 162

Class

UserCsvImportController
Provides methods to import CSV files and convert to users.

Namespace

Drupal\user_csv_import\Controller

Code

private function createUser($values) {
  $user = User::create($values);
  try {

    // If new user stores well, return the ID.
    if ($user
      ->save()) {
      return $user
        ->id();
    }
  } catch (EntityStorageException $e) {
    drupal_set_message(t('Could not create user %fname %lname (username: %uname) (email: %email); exception: %e', [
      '%e' => $e
        ->getMessage(),
      '%fname' => $values['field_name_first'],
      '%lname' => $values['field_name_last'],
      '%uname' => $values['name'],
      '%email' => $values['mail'],
    ]), 'error');
  }
  return FALSE;
}