From c9aa4e0955f52caa89ba3cdae4dbd0dc11a488ab Mon Sep 17 00:00:00 2001 From: Civiware Solutions Date: Tue, 26 Mar 2019 19:23:58 +0000 Subject: [PATCH] Fixed defaulting custom fields --- CRM/EntityTemplates/Utils.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/CRM/EntityTemplates/Utils.php b/CRM/EntityTemplates/Utils.php index 9d27a1a..f36ac0b 100644 --- a/CRM/EntityTemplates/Utils.php +++ b/CRM/EntityTemplates/Utils.php @@ -34,6 +34,14 @@ class CRM_EntityTemplates_Utils { * @param object $form */ public static function buildForm($formName, &$form) { + if ('CRM_Custom_Form_CustomDataByType' == $formName) { + if (empty($form->_entityTemplateId)) { + return; + } + $formValues = CRM_EntityTemplates_BAO_EntityTemplates::getFormValues($form->_entityTemplateId); + $form->setDefaults($formValues); + } + if (!empty($form->_entityTemplateValues)) { if ($form->_entityTemplate) { unset($form->_required); @@ -75,6 +83,17 @@ class CRM_EntityTemplates_Utils { $formValues = CRM_EntityTemplates_BAO_EntityTemplates::getFormValues($form->_entityTemplateId); $formValues['entity_template_id'] = $form->_entityTemplateId; $form->setDefaults($formValues); + CRM_Core_Resources::singleton()->addScript(" + CRM.$(function($) { + $(document).ajaxSend(function(event, jqxhr, settings) { + if (settings.url .indexOf('civicrm/custom') != -1) { + settings.url = settings.url + '&templateId={$form->_entityTemplateId}'; + } + }); + })", + 10, + 'html-header' + ); } CRM_Core_Region::instance('page-body')->add([ 'template' => 'CRM/EntityTemplates/EntityTemplate.tpl', @@ -114,7 +133,6 @@ class CRM_EntityTemplates_Utils { if ($id) { $entityParams['id'] = $id; } - civicrm_api3('EntityTemplates', 'create', $entityParams); // print message