From 6fb10123fdd6158ea9213b3b887b410f607609fe Mon Sep 17 00:00:00 2001
From: Liam Morland <lkmorlan@uwaterloo.ca>
Date: Tue, 9 Mar 2021 13:44:31 -0500
Subject: [PATCH] ISTWCMS-4025: Refactor code that skips user 1

---
 uw_cfg_common.module | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/uw_cfg_common.module b/uw_cfg_common.module
index 3695fbdb..a9b2abf1 100644
--- a/uw_cfg_common.module
+++ b/uw_cfg_common.module
@@ -174,25 +174,24 @@ function uw_cfg_common_webform_create(WebformInterface $webform) {
  * Remove the Manage link from the toolbar for authenticated users.
  */
 function uw_cfg_common_toolbar_alter(&$items) {
-
   // Get the current user.
   $current_user = \Drupal::currentUser();
 
-  // Ensure that the current user is not user1.
-  if ($current_user->id() !== '1') {
-
-    // Get the roles of the user.
-    $roles = $current_user->getRoles();
+  // No changes for user 1.
+  if ((int) $current_user->id() === 1) {
+    return;
+  }
 
-    // If there is only 1 role and that first role is authenticated, remove the
-    // manage link. If there are multiple roles then we know that they will have
-    // the Manage link, we are only removing the manage link for strictly
-    // authenticated users only.
-    if (count($roles) == 1 && $roles[0] == 'authenticated') {
+  // Get the roles of the user.
+  $roles = $current_user->getRoles();
 
-      // Remove the manage link.
-      unset($items['administration']);
-    }
+  // If there is only 1 role and that first role is authenticated, remove the
+  // manage link. If there are multiple roles then we know that they will have
+  // the Manage link, we are only removing the manage link for strictly
+  // authenticated users only.
+  if (count($roles) == 1 && $roles[0] == 'authenticated') {
+    // Remove the manage link.
+    unset($items['administration']);
   }
 }
 
-- 
GitLab