X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fprofiles%2Fdemo_umami%2Fmodules%2Fdemo_umami_content%2Fsrc%2FInstallHelper.php;fp=web%2Fcore%2Fprofiles%2Fdemo_umami%2Fmodules%2Fdemo_umami_content%2Fsrc%2FInstallHelper.php;h=01e998e9b3d3da7bc4485790f0e87750987e4130;hp=de061a6e369f8cd3da107a0de91fa9b31f9ad216;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php b/web/core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php index de061a6e3..01e998e9b 100644 --- a/web/core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php +++ b/web/core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php @@ -81,12 +81,41 @@ class InstallHelper implements ContainerInjectionInterface { * Imports default contents. */ public function importContent() { - $this->importArticles() + $this->importEditors() + ->importArticles() ->importRecipes() ->importPages() ->importBlockContent(); } + /** + * 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 $this + */ + 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; + } + /** * Imports articles. * @@ -104,6 +133,7 @@ class InstallHelper implements ContainerInjectionInterface { $values = [ 'type' => 'article', 'title' => $data['title'], + 'moderation_state' => 'published', ]; // Fields mapping starts. // Set Body Field. @@ -167,11 +197,11 @@ class InstallHelper implements ContainerInjectionInterface { 'type' => 'recipe', // Title field. 'title' => $data['title'], + 'moderation_state' => 'published', ]; // Set article author. if (!empty($data['author'])) { $values['uid'] = $this->getUser($data['author']); - $values['field_author'] = $values['uid']; } // Set node alias if exists. if (!empty($data['slug'])) { @@ -264,6 +294,7 @@ class InstallHelper implements ContainerInjectionInterface { $values = [ 'type' => 'page', 'title' => $data['title'], + 'moderation_state' => 'published', ]; // Fields mapping starts. // Set Body Field. @@ -401,10 +432,12 @@ class InstallHelper implements ContainerInjectionInterface { $user_storage = $this->entityTypeManager->getStorage('user'); $users = $user_storage->loadByProperties(['name' => $name]);; if (empty($users)) { - // Creating user without any email/password. + // 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();