Skip to content
Snippets Groups Projects
Commit 2af30652 authored by colemanw's avatar colemanw
Browse files

Merge pull request #1446 from colemanw/pcm

Fix api preferred_communication_method CRM-12548
parents a74fea9d fe18a93c
No related branches found
No related tags found
No related merge requests found
......@@ -570,29 +570,37 @@ class CRM_Utils_Array {
/**
* Like explode() but assumes that the $value is padded with $delim on left and right
*
* @param string|NULL $value
* @param mixed $values
* @param string $delim
* @return array|NULL
*/
static function explodePadded($value, $delim = CRM_Core_DAO::VALUE_SEPARATOR) {
if ($value === NULL) {
static function explodePadded($values, $delim = CRM_Core_DAO::VALUE_SEPARATOR) {
if ($values === NULL) {
return NULL;
}
return explode($delim, trim($value, $delim));
// If we already have an array, no need to continue
if (is_array($values)) {
return $values;
}
return explode($delim, trim((string) $values, $delim));
}
/**
* Like implode() but assumes that the $value is padded with $delim on left and right
* Like implode() but creates a string that is padded with $delim on left and right
*
* @param string|NULL $value
* @param mixed $values
* @param string $delim
* @return array|NULL
* @return string|NULL
*/
static function implodePadded($values, $delim = CRM_Core_DAO::VALUE_SEPARATOR) {
if ($values === NULL) {
return NULL;
}
return $delim . implode($delim, $values) . $delim;
// If we already have a string, strip $delim off the ends so it doesn't get added twice
if (is_string($values)) {
$values = trim($values, $delim);
}
return $delim . implode($delim, (array) $values) . $delim;
}
/**
......
......@@ -298,6 +298,11 @@ function _civicrm_api3_contact_check_params( &$params, $dupeCheck = true, $dupeE
break;
}
// Fixme: This really needs to be handled at a lower level. @See CRM-13123
if (isset($params['preferred_communication_method'])) {
$params['preferred_communication_method'] = CRM_Utils_Array::implodePadded($params['preferred_communication_method']);
}
if (CRM_Utils_Array::value('contact_sub_type', $params) && CRM_Utils_Array::value('contact_type', $params)) {
if (!(CRM_Contact_BAO_ContactType::isExtendsContactType($params['contact_sub_type'], $params['contact_type']))) {
throw new API_Exception("Invalid or Mismatched Contact SubType: " . implode(', ', (array)$params['contact_sub_type']));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment