Merge pull request #16484 from yashodha/dev_1580
[civicrm-core.git] / CRM / Core / Form / EntityFormTrait.php
index 61b800205de26f4a18f90cc925b85510483c8485..5ebf4441e8f8297156ed38c57b82400833172fdd 100644 (file)
  */
 trait CRM_Core_Form_EntityFormTrait {
 
+  /**
+   * The id of the object being edited / created.
+   *
+   * @var int
+   */
+  public $_id;
+
   /**
    * The entity subtype ID (eg. for Relationship / Activity)
    *
    * @var int
    */
-  protected $_entitySubTypeId;
+  protected $_entitySubTypeId = NULL;
 
   /**
    * Get entity fields for the entity to be added to the form.
@@ -71,6 +78,15 @@ trait CRM_Core_Form_EntityFormTrait {
     return $this->_id;
   }
 
+  /**
+   * Set the entity ID
+   *
+   * @param int $id The entity ID
+   */
+  public function setEntityId($id) {
+    $this->_id = $id;
+  }
+
   /**
    * Should custom data be suppressed on this form.
    *
@@ -83,17 +99,21 @@ trait CRM_Core_Form_EntityFormTrait {
   /**
    * Get the entity subtype ID being edited
    *
-   * @param $subTypeId
-   *
    * @return int|null
    */
-  public function getEntitySubTypeId($subTypeId) {
-    if ($subTypeId) {
-      return $subTypeId;
-    }
+  public function getEntitySubTypeId() {
     return $this->_entitySubTypeId;
   }
 
+  /**
+   * Set the entity subtype ID being edited
+   *
+   * @param $subTypeId
+   */
+  public function setEntitySubTypeId($subTypeId) {
+    $this->_entitySubTypeId = $subTypeId;
+  }
+
   /**
    * If the custom data is in the submitted data (eg. added via ajax loaded form) add to form.
    */
@@ -103,7 +123,7 @@ trait CRM_Core_Form_EntityFormTrait {
     }
     $customisableEntities = CRM_Core_SelectValues::customGroupExtends();
     if (isset($customisableEntities[$this->getDefaultEntity()])) {
-      CRM_Custom_Form_CustomData::addToForm($this);
+      CRM_Custom_Form_CustomData::addToForm($this, $this->getEntitySubTypeId());
     }
   }