Fix unserializing custom values to work during form reload
authorColeman Watts <coleman@civicrm.org>
Sun, 25 Apr 2021 02:58:46 +0000 (22:58 -0400)
committerColeman Watts <coleman@civicrm.org>
Sun, 25 Apr 2021 02:58:51 +0000 (22:58 -0400)
Fixes https://lab.civicrm.org/dev/core/-/issues/2506
MultiValued custom ContactRef fields were losing their value
during form reload if there was a validation error.

CRM/Core/BAO/CustomGroup.php

index 2ea810c725a72875eaad379a9074f7ba3aa85e65..8f0fea34950c44a24e96c71ed698e93fd151e7e3 100644 (file)
@@ -1355,8 +1355,13 @@ ORDER BY civicrm_custom_group.weight,
                 CRM_Utils_Array::formatArrayKeys($value);
                 $checkedValue = $value;
               }
+              // Serialized values from db
+              elseif ($value === '' || strpos($value, CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) {
+                $checkedValue = CRM_Utils_Array::explodePadded($value);
+              }
+              // Comma-separated values e.g. from a select2 widget during reload on form error
               else {
-                $checkedValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($value, 1, -1));
+                $checkedValue = explode(',', $value);
               }
               foreach ($checkedValue as $val) {
                 if ($val) {