From abf2b02bbe42a47549d2dea1a8ef567393499367 Mon Sep 17 00:00:00 2001
From: Liam Morland <lkmorlan@uwaterloo.ca>
Date: Wed, 15 Dec 2021 16:44:01 -0500
Subject: [PATCH] ISTWCMS-5253: Use hook_preprocess_HOOK() to set custom
 "access denied" message

Replace uw_cfg_common_webform_build_access_denied_alter() with
uw_cfg_common_preprocess_webform_access_denied().
---
 uw_cfg_common.module | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/uw_cfg_common.module b/uw_cfg_common.module
index 44a749ec..e2ec1473 100644
--- a/uw_cfg_common.module
+++ b/uw_cfg_common.module
@@ -1037,11 +1037,13 @@ function uw_cfg_common_get_user_ad_groups(): ?array {
 }
 
 /**
- * Implements hook_webform_build_access_denied_alter().
+ * Implements hook_preprocess_HOOK().
  *
  * Custom access denied messages with login/logout links.
  */
-function uw_cfg_common_webform_build_access_denied_alter(array &$build, WebformInterface $webform): void {
+function uw_cfg_common_preprocess_webform_access_denied(array &$variables): void {
+  $webform = $variables['webform'];
+
   $message = NULL;
   switch ($webform->getThirdPartySetting('uw_cfg_common', 'access_control_method')) {
     case 'auth':
@@ -1070,9 +1072,7 @@ function uw_cfg_common_webform_build_access_denied_alter(array &$build, WebformI
     // phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString
     $message = '<p>' . t($message, ['@url' => $url->toString()]) . '</p>';
 
-    $build['message'] = [
-      '#markup' => $message,
-    ];
+    $variables['message']['#markup'] = $message;
   }
 }
 
-- 
GitLab