private function UserCsvImportController::createUser in User CSV import 1.0.x
Same name and namespace in other branches
- 8 src/Controller/UserCsvImportController.php \Drupal\user_csv_import\Controller\UserCsvImportController::createUser()
- 2.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
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\ControllerCode
private function createUser($values) {
if (user_load_by_mail($values['mail']) === FALSE) {
$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 (username: %uname) (email: %email); exception: %e', [
'%e' => $e
->getMessage(),
'%uname' => $values['name'],
'%email' => $values['mail'],
]), 'error');
}
}
else {
$message = t('Could not create user (username: %uname) (email: %email). Email already in use', [
'%uname' => $values['name'],
'%email' => $values['mail'],
]);
// put in logs
\Drupal::logger('usercsvimport')
->notice($message);
// output to user submitting
drupal_set_message($message, 'error');
}
return FALSE;
}