Add function to set entitySubType for entity forms
authorMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Mon, 2 Dec 2019 12:45:57 +0000 (12:45 +0000)
committerMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Tue, 3 Dec 2019 20:22:42 +0000 (20:22 +0000)
CRM/Case/Form/Case.php
CRM/Core/Form/EntityFormTrait.php
CRM/Custom/Form/CustomData.php
templates/CRM/Activity/Form/Activity.tpl

index 0d43ed1912af147d4d6b7bbe35ad5631692e09a4..05e832c744544b54dee470f810876e9d74bd7a29 100644 (file)
@@ -93,20 +93,6 @@ class CRM_Case_Form_Case extends CRM_Core_Form {
     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.
    */
index 61b800205de26f4a18f90cc925b85510483c8485..15ff60830a797184fd2a658b2b88cbc2937a128b 100644 (file)
@@ -21,7 +21,7 @@ trait CRM_Core_Form_EntityFormTrait {
    *
    * @var int
    */
-  protected $_entitySubTypeId;
+  protected $_entitySubTypeId = NULL;
 
   /**
    * Get entity fields for the entity to be added to the form.
@@ -83,17 +83,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 +107,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());
     }
   }
 
index 8bdc0d79ace599299bbaa2604c471cfc1424ae78..e502c72e15b1ffb03bfe191184ec4279f9551901 100644 (file)
@@ -29,7 +29,7 @@ class CRM_Custom_Form_CustomData {
    *   $params['custom'] = CRM_Core_BAO_CustomField::postProcess($submitted, $this->_id, $this->getDefaultEntity());
    *
    * @param CRM_Core_Form $form
-   * @param null|string $subType values stored in civicrm_custom_group.extends_entity_column_value
+   * @param null|string $entitySubType values stored in civicrm_custom_group.extends_entity_column_value
    *   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
@@ -37,15 +37,12 @@ class CRM_Custom_Form_CustomData {
    *
    * @throws \CRM_Core_Exception
    */
-  public static function addToForm(&$form, $subType = NULL, $subName = NULL, $groupCount = 1, $contact_id = NULL) {
+  public static function addToForm(&$form, $entitySubType = 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.
-    // However, if it is only partially converted (ie. we've switched customdata to use CRM_Custom_Form_CustomData)
-    // it won't, so we check if we have a subtype before calling the function.
-    $entitySubType = NULL;
-    if ($subType) {
-      $entitySubType = $form->getEntitySubTypeId($subType);
+    // If the form has been converted to use entityFormTrait then getEntitySubTypeId() will exist.
+    if (method_exists($form, 'getEntitySubTypeId') && empty($entitySubType)) {
+      $entitySubType = $form->getEntitySubTypeId();
     }
 
     if ($form->getAction() == CRM_Core_Action::VIEW) {
index 5b2e22a499a97615984ecb407a1a897308d81593..a02f93f15f5e1dea7cb72e739a51ee7b8f151e8b 100644 (file)
       {if $action eq 4}
         {include file="CRM/Custom/Page/CustomDataView.tpl"}
       {else}
-        <div id="customData"></div>
         {include file="CRM/common/customDataBlock.tpl"}
       {/if}
     </td>