From 01f1409c41cf0f9202763d15f3c3e5ae523e191a Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 24 Apr 2021 22:58:46 -0400 Subject: [PATCH] Fix unserializing custom values to work during form reload 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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 2ea810c725..8f0fea3495 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -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) { -- 2.25.1