protected function InstallHelper::getUser in Drupal 9
Same name and namespace in other branches
- 8 core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php \Drupal\demo_umami_content\InstallHelper::getUser()
Looks up a user by name, if it is missing the user is created.
Parameters
string $name: Username.
Return value
int User ID.
4 calls to InstallHelper::getUser()
- InstallHelper::processArticle in core/
profiles/ demo_umami/ modules/ demo_umami_content/ src/ InstallHelper.php - Process article data into article node structure.
- InstallHelper::processImage in core/
profiles/ demo_umami/ modules/ demo_umami_content/ src/ InstallHelper.php - Process images into media entities.
- InstallHelper::processPage in core/
profiles/ demo_umami/ modules/ demo_umami_content/ src/ InstallHelper.php - Process pages data into page node structure.
- InstallHelper::processRecipe in core/
profiles/ demo_umami/ modules/ demo_umami_content/ src/ InstallHelper.php - Process recipe data into recipe node structure.
File
- core/
profiles/ demo_umami/ modules/ demo_umami_content/ src/ InstallHelper.php, line 810
Class
- InstallHelper
- Defines a helper class for importing default content.
Namespace
Drupal\demo_umami_contentCode
protected function getUser($name) {
$user_storage = $this->entityTypeManager
->getStorage('user');
$users = $user_storage
->loadByProperties([
'name' => $name,
]);
if (empty($users)) {
// Creating user without any password.
$user = $user_storage
->create([
'name' => $name,
'status' => 1,
'roles' => [
'author',
],
'mail' => mb_strtolower(str_replace(' ', '.', $name)) . '@example.com',
]);
$user
->enforceIsNew();
$user
->save();
$this
->storeCreatedContentUuids([
$user
->uuid() => 'user',
]);
return $user
->id();
}
$user = reset($users);
return $user
->id();
}