Convert case/case activity forms to standard customData template
authorMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Mon, 7 Jan 2019 17:51:24 +0000 (17:51 +0000)
committerMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Mon, 7 Jan 2019 22:11:51 +0000 (22:11 +0000)
CRM/Case/Form/Case.php
templates/CRM/Case/Form/Activity.tpl
templates/CRM/Case/Form/Case.tpl

index 9e3e2897c35b516ad5a293f6f737d2e322c757d4..d8b2ae47ae5e143f5cc3845e60dd4d58905dcdbd 100644 (file)
@@ -83,6 +83,36 @@ class CRM_Case_Form_Case extends CRM_Core_Form {
    */
   public $_caseTypeId = NULL;
 
+  /**
+   * Explicitly declare the entity api name.
+   */
+  public function getDefaultEntity() {
+    return 'Case';
+  }
+
+  /**
+   * Get the entity id being edited.
+   *
+   * @return int|null
+   */
+  public function getEntityId() {
+    return $this->_caseId;
+  }
+
+  /**
+   * Get the entity subtype ID being edited
+   *
+   * @param $subTypeId
+   *
+   * @return int|null
+   */
+  public function getEntitySubTypeId($subTypeId) {
+    if ($subTypeId) {
+      return $subTypeId;
+    }
+    return $this->_caseTypeId;
+  }
+
   /**
    * Build the form object.
    */
@@ -170,18 +200,15 @@ class CRM_Case_Form_Case extends CRM_Core_Form {
     $session = CRM_Core_Session::singleton();
     $this->_currentUserId = $session->get('userID');
 
-    //when custom data is included in this page
+    //Add activity custom data is included in this page
     CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity');
     $className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}";
     $className::preProcess($this);
     $activityGroupTree = $this->_groupTree;
 
-    // for case custom fields to populate with defaults
-    if (!empty($_POST['hidden_custom'])) {
-      $params = CRM_Utils_Request::exportValues();
-      CRM_Custom_Form_CustomData::preProcess($this, NULL, CRM_Utils_Array::value('case_type_id', $params, $this->_caseTypeId), 1, 'Case', $this->_caseId);
-      CRM_Custom_Form_CustomData::buildQuickForm($this);
-    }
+    // Add case custom data to form
+    $caseTypeId = CRM_Utils_Array::value('case_type_id', CRM_Utils_Request::exportValues(), $this->_caseTypeId);
+    CRM_Custom_Form_CustomData::addToForm($this, $caseTypeId);
 
     // so that grouptree is not populated with case fields, since the grouptree is used
     // for populating activity custom fields.
@@ -227,10 +254,9 @@ class CRM_Case_Form_Case extends CRM_Core_Form {
       return;
     }
 
-    //need to assign custom data type and subtype to the template
-    $this->assign('customDataType', 'Case');
-
+    // Add the activity custom data to the form
     CRM_Custom_Form_CustomData::buildQuickForm($this);
+
     // we don't want to show button on top of custom form
     $this->assign('noPreCustomButton', TRUE);
 
index aa8d78cb5c6927223f2842367f483edcaa127f79..fff7efa8341003439ec3b6ac332eea95f07f7bb4 100644 (file)
               </tr>
               {/if}
               <tr>
-                <td colspan="2"><div id="customData"></div></td>
+                <td colspan="2">{include file="CRM/common/customDataBlock.tpl"}</td>
               </tr>
               {if NOT $activityTypeFile}
                 <tr class="crm-case-activity-form-block-details">
 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
 
   {if $action eq 1 or $action eq 2}
-    {*include custom data js file*}
-    {include file="CRM/common/customData.tpl"}
     {literal}
     <script type="text/javascript">
-    CRM.$(function($) {
-      var doNotNotifyAssigneeFor = {/literal}{$doNotNotifyAssigneeFor|@json_encode}{literal};
-      $('#activity_type_id').change(function() {
-        if ($.inArray($(this).val(), doNotNotifyAssigneeFor) != -1) {
-          $('#notify_assignee_msg').hide();
-        }
-        else {
-          $('#notify_assignee_msg').show();
-        }
+      CRM.$(function($) {
+        var doNotNotifyAssigneeFor = {/literal}{$doNotNotifyAssigneeFor|@json_encode}{literal};
+        $('#activity_type_id').change(function() {
+          if ($.inArray($(this).val(), doNotNotifyAssigneeFor) != -1) {
+            $('#notify_assignee_msg').hide();
+          }
+          else {
+            $('#notify_assignee_msg').show();
+          }
+        });
       });
-
-      {/literal}
-      {if $customDataSubType}
-        CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
-        {else}
-        CRM.buildCustomData( '{$customDataType}' );
-      {/if}
-      {literal}
-    });
     </script>
     {/literal}
   {/if}
index 08d2d004ed552ed451a2048e9ac33dba96e34342..fb000fbe7938982c2fbeced31f8de4cdd33333c5 100644 (file)
 
 <tr class="crm-case-form-block-custom_data">
     <td colspan="2">
-        <div id="customData"></div>
+      {include file="CRM/common/customDataBlock.tpl"}
     </td>
 </tr>
 
 </table>
 {/if}
 
-{if $action eq 1}
-    {*include custom data js file*}
-    {include file="CRM/common/customData.tpl"}
-    {literal}
-      <script type="text/javascript">
-      CRM.$(function($) {
-           var customDataSubType = $('#case_type_id').val();
-           if ( customDataSubType ) {
-              CRM.buildCustomData( {/literal}'{$customDataType}'{literal}, customDataSubType );
-           } else {
-              CRM.buildCustomData( {/literal}'{$customDataType}'{literal} );
-           }
-       });
-       </script>
-     {/literal}
-{/if}
-
 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
 
 </div>