diff --git a/uw_cfg_common.module b/uw_cfg_common.module
index 44a749ecd32bbe679a9e1103bf2f4d069d7155e9..e2ec14735d34b8d92e1d591c945fb91d016e3712 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;
   }
 }