From a3f5a0d6e416953b585767853148877e18b11f35 Mon Sep 17 00:00:00 2001
From: Liam Morland <lkmorlan@uwaterloo.ca>
Date: Tue, 27 Jul 2021 10:51:24 -0400
Subject: [PATCH] ISTWCMS-4960: Give default access to Webforms that have no
 access to create submissions

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

diff --git a/uw_cfg_common.install b/uw_cfg_common.install
index 7ade6e2f..7c141f02 100644
--- a/uw_cfg_common.install
+++ b/uw_cfg_common.install
@@ -428,6 +428,29 @@ function uw_cfg_common_update_8103() {
 
 }
 
+/*
+ * Give default access to Webforms that have no access to create submissions.
+ */
+function uw_cfg_common_update_8104() {
+  $counter = 0;
+
+  $webforms = \Drupal::entityTypeManager()->getStorage('webform')->loadMultiple();
+  foreach ($webforms as $webform) {
+    $access = $webform->getAccessRules();
+    if (empty($access['create']['roles'])) {
+      $access['create']['roles'] = [
+        'anonymous',
+        'authenticated',
+      ];
+      $webform->setAccessRules($access);
+      $webform->save();
+      $counter++;
+    }
+  }
+
+  return t('Set default access for @counter Webforms.', ['@counter' => $counter]);
+}
+
 /**
  * Implements hook_update_dependencies().
  */
-- 
GitLab