From 96265bc83dcccf748bee492ac2fca25f31111869 Mon Sep 17 00:00:00 2001
From: Eric Bremner <ebremner@uwaterloo.ca>
Date: Thu, 22 Jul 2021 19:12:17 +0000
Subject: [PATCH] ISTWCMS-4954: adding role creation and permission setting to
 install hook

---
 uw_cfg_common.install | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/uw_cfg_common.install b/uw_cfg_common.install
index b98753db..5f00d8b9 100644
--- a/uw_cfg_common.install
+++ b/uw_cfg_common.install
@@ -10,11 +10,50 @@ use Drupal\node\Entity\Node;
 use Drupal\uw_cfg_common\UwPermissions\UwPermissions;
 use Drupal\user\Entity\Role;
 use Drupal\Core\Config\FileStorage;
+use Drupal\uw_cfg_common\UwRoles\UwRoles;
 
 /**
  * Implements hook_install().
  */
 function uw_cfg_common_install() {
+
+  // Get the role ids for UW roles.
+  $uw_rids = UwRoles::getUwRoleIds();
+
+  // Step through each of the rids and create
+  // role and set permissions.
+  foreach ($uw_rids as $uw_rid) {
+
+    // Create the role.
+    $role = Role::create(
+      [
+        'id' => $uw_rid,
+        'label' => UwRoles::getUwRoleLabel($uw_rid),
+      ]
+    );
+    $role->save();
+
+    // Get the info about the role.
+    $uw_role = UwRoles::getUwRole($uw_rid);
+
+    // Set the permissions for the role.
+    UwRoles::setUwPermissions($uw_role);
+  }
+
+  // Get the role ids for Drupal roles.
+  $drupal_rids = UwRoles::getDrupalRoleIds();
+
+  // Step through each of the Drupal roles and
+  // set the permissions.
+  foreach ($drupal_rids as $drupal_rid) {
+
+    // Get the info about the role.
+    $uw_role = UwRoles::getUwRole($drupal_rid);
+
+    // Set the permissions for the role.
+    UwRoles::setUwPermissions($uw_role);
+  }
+
   $permissions_to_process = [
     'Blog' => [
       'Use content type' => [
-- 
GitLab