function InstallHelper::importEditors

Same name in other branches
  1. 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 314

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.