Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / profiles / demo_umami / modules / demo_umami_content / src / InstallHelper.php
index de061a6e369f8cd3da107a0de91fa9b31f9ad216..01e998e9b3d3da7bc4485790f0e87750987e4130 100644 (file)
@@ -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();