From 882a1be21c5296f369b8a750c8a1ced929f599ee Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 22 Sep 2016 16:14:34 -0400 Subject: [PATCH] CRM-19403 - Pass extra data back to entityRef widget when creating new contact --- CRM/Profile/Form/Edit.php | 17 ++++++++++++++--- js/Common.js | 4 +++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CRM/Profile/Form/Edit.php b/CRM/Profile/Form/Edit.php index dd9e1c5f53..2032b31024 100644 --- a/CRM/Profile/Form/Edit.php +++ b/CRM/Profile/Form/Edit.php @@ -48,6 +48,7 @@ class CRM_Profile_Form_Edit extends CRM_Profile_Form { protected $_context; protected $_blockNo; protected $_prefix; + protected $returnExtra = array(); /** * Pre processing work done here. @@ -71,6 +72,10 @@ class CRM_Profile_Form_Edit extends CRM_Profile_Form { //set the prefix $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->assign('context', $this->_context); if ($this->_blockNo) { @@ -258,9 +263,15 @@ SELECT module,is_reserved public function postProcess() { parent::postProcess(); - $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_id, 'display_name'); - $sortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_id, 'sort_name'); - $this->ajaxResponse['label'] = $sortName; + // 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); + } // When saving (not deleting) and not in an ajax popup if (empty($_POST[$this->_deleteButtonName]) && $this->_context != 'dialog') { diff --git a/js/Common.js b/js/Common.js index 91faa35643..0ce40ab8e5 100644 --- a/js/Common.js +++ b/js/Common.js @@ -532,8 +532,10 @@ if (!CRM.vars) CRM.vars = {}; $('#select2-drop') .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) : ''); $el.select2('close'); - CRM.loadForm($(this).attr('href'), { + CRM.loadForm(formUrl, { dialog: {width: 500, height: 220} }).on('crmFormSuccess', function(e, data) { if (data.status === 'success' && data.id) { -- 2.25.1