Fix unserializing custom values to work during form reload
[civicrm-core.git] / 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) {