You are here

protected function InstallHelper::importEditors in Drupal 10

Same name and namespace in other branches
  1. 8 core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php \Drupal\demo_umami_content\InstallHelper::importEditors()
  2. 9 core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php \Drupal\demo_umami_content\InstallHelper::importEditors()

Imports editors.

Other users are created as their content is imported. However, editors don't have their own content so are created here instead.

Return value

$this

File

core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php, line 302

Class

InstallHelper
Defines a helper class for importing default content.

Namespace

Drupal\demo_umami_content

Code

protected function importEditors() {
  $user_storage = $this->entityTypeManager
    ->getStorage('user');
  $editors = [
    'Margaret Hopper',
    'Grace Hamilton',
  ];
  foreach ($editors as $name) {
    $user = $user_storage
      ->create([
      'name' => $name,
      'status' => 1,
      'roles' => [
        'editor',
      ],
      'mail' => mb_strtolower(str_replace(' ', '.', $name)) . '@example.com',
    ]);
    $user
      ->enforceIsNew();
    $user
      ->save();
    $this
      ->storeCreatedContentUuids([
      $user
        ->uuid() => 'user',
    ]);
  }
  return $this;
}