Support customdata subtype on entityform (for activity/relationship types)
authorMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Tue, 18 Dec 2018 10:01:49 +0000 (10:01 +0000)
committerMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Tue, 18 Dec 2018 10:01:49 +0000 (10:01 +0000)
CRM/Core/Form/EntityFormTrait.php
CRM/Custom/Form/CustomData.php

index 2f1bdefb0d873f6b6d145c7beb161ebb72aa4a3d..a1133f5dfea706c7e40a4ce2c13eed11b0763424 100644 (file)
 
 trait CRM_Core_Form_EntityFormTrait {
 
+  /**
+   * The entity subtype ID (eg. for Relationship / Activity)
+   *
+   * @var int
+   */
+  protected $_entitySubTypeId;
+
   /**
    * Get entity fields for the entity to be added to the form.
    *
@@ -66,6 +73,21 @@ trait CRM_Core_Form_EntityFormTrait {
   public function getEntityId() {
     return $this->_id;
   }
+
+  /**
+   * Get the entity subtype ID being edited
+   *
+   * @param $subTypeId
+   *
+   * @return int|null
+   */
+  public function getEntitySubTypeId($subTypeId) {
+    if ($subTypeId) {
+      return $subTypeId;
+    }
+    return $this->_entitySubTypeId;
+  }
+
   /**
    * If the custom data is in the submitted data (eg. added via ajax loaded form) add to form.
    */
index 4c9b3499a80abf3f83c593b45fba63f0152b271c..f4528ceac3e09a70a5b9a7c6e404bae47c87febc 100644 (file)
@@ -55,16 +55,17 @@ class CRM_Custom_Form_CustomData {
   public static function addToForm(&$form, $subType = NULL, $subName = NULL, $groupCount = 1) {
     $entityName = $form->getDefaultEntity();
     $entityID = $form->getEntityId();
+    $entitySubType = $form->getEntitySubTypeId($subType);
 
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
-      self::preProcess($form, $subName, $subType, $groupCount, $entityName, $entityID);
+      self::preProcess($form, $subName, $entitySubType, $groupCount, $entityName, $entityID);
       self::buildQuickForm($form);
       self::setDefaultValues($form);
     }
     // need to assign custom data type and subtype to the template
     $form->assign('customDataType', $entityName);
-    $form->assign('customDataSubType', $subType);
+    $form->assign('customDataSubType', $entitySubType);
     $form->assign('entityID', $entityID);
   }