function InstallHelper::getUser
Same name in other branches
- 9 core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php \Drupal\demo_umami_content\InstallHelper::getUser()
- 10 core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php \Drupal\demo_umami_content\InstallHelper::getUser()
- 11.x 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 820
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();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.