Fix e-notice on contact create for low-permissioned user
authorcolemanw <coleman@civicrm.org>
Tue, 2 Jan 2024 15:08:53 +0000 (10:08 -0500)
committercolemanw <coleman@civicrm.org>
Tue, 2 Jan 2024 15:08:53 +0000 (10:08 -0500)
This cleans up some very messy code which was emitting e-notices when the 'group' key was missing.
This can happen when the current user does not have permissions to add contacts to groups.

CRM/Contact/Form/Contact.php

index 169136292876a004c51145c43c11c3b4df77a84a..d9059f9391cdd658c0b2dc6371b20fb3d56c0ec2 100644 (file)
@@ -987,14 +987,9 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
       $params['preferred_communication_method'] = 'null';
     }
 
-    $group = $params['group'] ?? NULL;
-    $params['group'] = ($params['group'] == '') ? [] : $params['group'];
-    if (!empty($group)) {
-      $group = is_array($group) ? $group : explode(',', $group);
-      $params['group'] = [];
-      foreach ($group as $key => $value) {
-        $params['group'][$value] = 1;
-      }
+    if (array_key_exists('group', $params)) {
+      $group = is_array($params['group']) ? $params['group'] : explode(',', $params['group']);
+      $params['group'] = array_fill_keys($group, 1);
     }
 
     if (!empty($params['image_URL'])) {