Merge pull request #23028 from civicrm/5.48
[civicrm-core.git] / CRM / Core / Form / EntityFormTrait.php
index 15ff60830a797184fd2a658b2b88cbc2937a128b..ccf5522788446357b8b28da2f4759aef602f5180 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)
    *
@@ -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.
    *
@@ -121,6 +137,16 @@ trait CRM_Core_Form_EntityFormTrait {
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->addEntityFieldsToTemplate();
+    foreach ($this->entityFields as $index => $fields) {
+      $this->entityFields[$index] = array_merge([
+        'template' => '',
+        'help' => [],
+        'pre_html_text' => '',
+        'post_html_text' => '',
+        'description' => '',
+        'documentation_link' => '',
+      ], $fields);
+    }
     $this->assign('entityFields', $this->entityFields);
     $this->assign('entityID', $this->getEntityId());
     $this->assign('entityInClassFormat', strtolower(str_replace('_', '-', $this->getDefaultEntity())));
@@ -240,7 +266,7 @@ trait CRM_Core_Form_EntityFormTrait {
         if ($spec['localizable']) {
           $this->entityFields[$fieldName]['is_add_translate_dialog'] = TRUE;
         }
-        if (empty($spec['html'])) {
+        if (empty($spec['html']['type'])) {
           $this->entityFields[$fieldName]['not-auto-addable'] = TRUE;
         }
       }