dev/core#752 Add cid paramater when loading custom data via backend forms so that...
authorSeamus Lee <seamuslee001@gmail.com>
Sun, 11 Aug 2019 06:28:48 +0000 (16:28 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Sun, 11 Aug 2019 22:06:39 +0000 (08:06 +1000)
Add in handling for cid not being set

Fix assign of cid and switch to using javascript if rather than smarty

CRM/Activity/Form/Activity.php
CRM/Custom/Form/CustomData.php
CRM/Custom/Form/CustomDataByType.php
templates/CRM/common/customData.tpl
templates/CRM/common/customDataBlock.tpl

index dc6718406bf50af730ff03acaa203095dc8043e1..cda77aee1d92ad9c35e6304d5ac57db6ed8b9e4f 100644 (file)
@@ -483,6 +483,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
     }
 
     // when custom data is included in this page
+    $this->assign('cid', $this->_currentlyViewedContactId);
     if (!empty($_POST['hidden_custom'])) {
       // We need to set it in the session for the code below to work.
       // CRM-3014
@@ -666,7 +667,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
     $element = &$this->add('select', 'activity_type_id', ts('Activity Type'),
       ['' => '- ' . ts('select') . ' -'] + $this->_fields['followup_activity_type_id']['attributes'],
       FALSE, [
-        'onchange' => "CRM.buildCustomData( 'Activity', this.value );",
+        'onchange' => "CRM.buildCustomData( 'Activity', this.value, false, false, false, false, false, false, {$this->_currentlyViewedContactId});",
         'class' => 'crm-select2 required',
       ]
     );
index 42d6a5372aed37dadecccd22b0b734965cc192fc..f508e14138666dea66b238c1079cf7c4fcbd0308 100644 (file)
@@ -49,10 +49,11 @@ class CRM_Custom_Form_CustomData {
    *   e.g Student for contact type
    * @param null|string $subName value in civicrm_custom_group.extends_entity_column_id
    * @param null|int $groupCount number of entities that could have custom data
+   * @param null|int $contact_id contact ID associated with the custom data.
    *
    * @throws \CRM_Core_Exception
    */
-  public static function addToForm(&$form, $subType = NULL, $subName = NULL, $groupCount = 1) {
+  public static function addToForm(&$form, $subType = NULL, $subName = NULL, $groupCount = 1, $contact_id = NULL) {
     $entityName = $form->getDefaultEntity();
     $entityID = $form->getEntityId();
     // FIXME: If the form has been converted to use entityFormTrait then getEntitySubTypeId() will exist.
@@ -80,6 +81,7 @@ class CRM_Custom_Form_CustomData {
     $form->assign('customDataType', $entityName);
     $form->assign('customDataSubType', $entitySubType);
     $form->assign('entityID', $entityID);
+    $form->assign('cid', $contact_id);
   }
 
   /**
index c88a29fb16226d79cdb50309ff28f661c6a1ba79..a2f162d972f28971fa34df6dc8944c59e6f1224b 100644 (file)
  */
 class CRM_Custom_Form_CustomDataByType extends CRM_Core_Form {
 
+  /**
+   * Contact ID associated with the Custom Data
+   *
+   * @var int
+   */
+  public $_contactID = NULL;
+
   /**
    * Preprocess function.
    */
@@ -46,6 +53,7 @@ class CRM_Custom_Form_CustomDataByType extends CRM_Core_Form {
     $this->_subName = CRM_Utils_Request::retrieve('subName', 'String');
     $this->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive');
     $this->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive');
+    $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive');
     $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive');
     $this->_onlySubtype = CRM_Utils_Request::retrieve('onlySubtype', 'Boolean');
     $this->_action = CRM_Utils_Request::retrieve('action', 'Alphanumeric');
index 68208c9995597766b3681e95b13d4145a86282c3..867013c0d4154170adcd76089f9fad2083dbca6d 100644 (file)
@@ -26,7 +26,7 @@
 {literal}
 <script type="text/javascript">
   (function($) {
-    CRM.buildCustomData = function (type, subType, subName, cgCount, groupID, isMultiple, onlySubtype) {
+    CRM.buildCustomData = function (type, subType, subName, cgCount, groupID, isMultiple, onlySubtype, cid) {
       var dataUrl = CRM.url('civicrm/custom', {type: type}),
         prevCount = 1,
         fname = '#customData',
         dataUrl += '&qf=' + '{$qfKey}';
       {/if}
       {if $action}
-      dataUrl += '&action=' + '{$action}';
+        dataUrl += '&action=' + '{$action}';
       {/if}
       {literal}
+      if (cid) {
+        dataUrl += '&cid=' + cid;
+      }
 
       if (!cgCount) {
         cgCount = 1;
index d98b4a996af720665eeeb5c4a21fbcf2dbd006b2..ca3848df706259a29bd4951d286bb27b8469c6bd 100644 (file)
@@ -2,14 +2,15 @@
   <div id="customData"></div>
   {*include custom data js file*}
   {include file="CRM/common/customData.tpl"}
+  {assign var='cid' value=$cid|default:'false'}
   {literal}
   <script type="text/javascript">
     CRM.$(function($) {
       {/literal}
       {if $customDataSubType}
-        CRM.buildCustomData('{$customDataType}', {$customDataSubType});
+        CRM.buildCustomData('{$customDataType}', {$customDataSubType}, false, false, false, false, false, {$cid});
       {else}
-        CRM.buildCustomData('{$customDataType}');
+        CRM.buildCustomData('{$customDataType}', false, false, false, false, false, false, {$cid});
       {/if}
       {literal}
     });