CRM-19403 - Pass extra data back to entityRef widget when creating new contact
authorColeman Watts <coleman@civicrm.org>
Thu, 22 Sep 2016 20:14:34 +0000 (16:14 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 29 Sep 2016 16:53:38 +0000 (12:53 -0400)
CRM/Profile/Form/Edit.php
js/Common.js

index dd9e1c5f5328a4ffc40b96f2e7c92f27af0d11ea..2032b31024ad84cb569280e558e456fc2d821225 100644 (file)
@@ -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') {
index 91faa3564322975f153e7d874ae34e155588072a..0ce40ab8e5b5dbf544f825f2cd3eaee3031e68f8 100644 (file)
@@ -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) {