From: Coleman Watts Date: Thu, 29 Sep 2016 17:10:07 +0000 (-0400) Subject: CRM-19403 - Cleaner approach to passing extra data from profiles X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2b63c577129780f50ca8a9ce5847e7aa0841c6ce;p=civicrm-core.git CRM-19403 - Cleaner approach to passing extra data from profiles --- diff --git a/CRM/Profile/Form/Edit.php b/CRM/Profile/Form/Edit.php index 2032b31024..27aac2017c 100644 --- a/CRM/Profile/Form/Edit.php +++ b/CRM/Profile/Form/Edit.php @@ -48,7 +48,7 @@ class CRM_Profile_Form_Edit extends CRM_Profile_Form { protected $_context; protected $_blockNo; protected $_prefix; - protected $returnExtra = array(); + protected $returnExtra; /** * Pre processing work done here. @@ -73,8 +73,7 @@ class CRM_Profile_Form_Edit extends CRM_Profile_Form { $this->_prefix = CRM_Utils_Request::retrieve('prefix', 'String', $this); // Fields for the EntityRef widget - $returnExtra = CRM_Utils_Request::retrieve('returnExtra', 'String', $this); - $this->returnExtra = $returnExtra ? explode(',', $returnExtra) : array(); + $this->returnExtra = CRM_Utils_Request::retrieve('returnExtra', 'String', $this); $this->assign('context', $this->_context); @@ -264,13 +263,15 @@ SELECT module,is_reserved parent::postProcess(); // Send back data for the EntityRef widget - $contact = civicrm_api3('Contact', 'getsingle', array( - 'id' => $this->_id, - 'return' => array_merge(array('sort_name'), $this->returnExtra), - )); - $this->ajaxResponse['label'] = $contact['sort_name']; - foreach ($this->returnExtra as $field) { - $this->ajaxResponse['extra'][$field] = CRM_Utils_Array::value($field, $contact); + if ($this->returnExtra) { + $contact = civicrm_api3('Contact', 'getsingle', array( + 'id' => $this->_id, + 'return' => $this->returnExtra, + )); + foreach (explode(',', $this->returnExtra) as $field) { + $field = trim($field); + $this->ajaxResponse['extra'][$field] = CRM_Utils_Array::value($field, $contact); + } } // When saving (not deleting) and not in an ajax popup diff --git a/js/Common.js b/js/Common.js index 0ce40ab8e5..bd878d61d8 100644 --- a/js/Common.js +++ b/js/Common.js @@ -533,13 +533,14 @@ if (!CRM.vars) CRM.vars = {}; .off('.crmEntity') .on('click.crmEntity', 'a.crm-add-entity', function(e) { var extra = $el.data('api-params').extra, - formUrl = $(this).attr('href') + (extra ? ('&returnExtra=' + extra) : ''); + formUrl = $(this).attr('href') + '&returnExtra=display_name,sort_name' + (extra ? (',' + extra) : ''); $el.select2('close'); CRM.loadForm(formUrl, { dialog: {width: 500, height: 220} }).on('crmFormSuccess', function(e, data) { if (data.status === 'success' && data.id) { - CRM.status(ts('%1 Created', {1: data.label})); + data.label = data.extra.sort_name; + CRM.status(ts('%1 Created', {1: data.extra.display_name})); if ($el.select2('container').hasClass('select2-container-multi')) { var selection = $el.select2('data'); selection.push(data);