From 2f33ec4ad6574eaf47c9b8a0920ecc5ae3d5724d Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Wed, 30 Mar 2022 20:49:56 -0400 Subject: [PATCH] Add support for financial account custom fields --- CRM/Financial/BAO/FinancialAccount.php | 4 ++++ CRM/Financial/Form/FinancialAccount.php | 17 +++++++++++++++++ .../CRM/Financial/Form/FinancialAccount.tpl | 3 +++ 3 files changed, 24 insertions(+) diff --git a/CRM/Financial/BAO/FinancialAccount.php b/CRM/Financial/BAO/FinancialAccount.php index 07198cb149..b92970a8d6 100644 --- a/CRM/Financial/BAO/FinancialAccount.php +++ b/CRM/Financial/BAO/FinancialAccount.php @@ -97,6 +97,10 @@ class CRM_Financial_BAO_FinancialAccount extends CRM_Financial_DAO_FinancialAcco $financialAccount->copyValues($params); $financialAccount->save(); + if (!empty($params['custom']) && is_array($params['custom'])) { + CRM_Core_BAO_CustomValueTable::store($params['custom'], static::$_tableName, $financialAccount->id, $op); + } + // invoke post hook $op = 'create'; if (!empty($params['id'])) { diff --git a/CRM/Financial/Form/FinancialAccount.php b/CRM/Financial/Form/FinancialAccount.php index ea6e127caf..93f4aa668b 100644 --- a/CRM/Financial/Form/FinancialAccount.php +++ b/CRM/Financial/Form/FinancialAccount.php @@ -19,6 +19,7 @@ * This class generates form components for Financial Account */ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form { + use CRM_Core_Form_EntityFormTrait; /** * Flag if its a AR account type. @@ -27,12 +28,25 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form { */ protected $_isARFlag = FALSE; + /** + * Explicitly declare the entity api name. + * + * @return string + */ + public function getDefaultEntity() { + return 'FinancialAccount'; + } + /** * Set variables up before form is built. */ public function preProcess() { parent::preProcess(); + // Add custom data to form + CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'FinancialAccount', $this->_id); + CRM_Custom_Form_CustomData::buildQuickForm($this); + if ($this->_id) { $params = [ 'id' => $this->_id, @@ -101,6 +115,7 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form { } } + $this->addCustomDataToForm(); if ($this->_action == CRM_Core_Action::UPDATE && CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $this->_id, 'is_reserved') ) { @@ -159,6 +174,7 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form { */ public function setDefaultValues() { $defaults = parent::setDefaultValues(); + $defaults = array_merge($defaults, CRM_Custom_Form_CustomData::setDefaultValues($this)); if ($this->_action & CRM_Core_Action::ADD) { $defaults['contact_id'] = CRM_Core_BAO_Domain::getDomain()->contact_id; } @@ -180,6 +196,7 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form { else { // store the submitted values in an array $params = $this->exportValues(); + $params['custom'] = CRM_Core_BAO_CustomField::postProcess($this->_submitValues, $this->_id, 'FinancialAccount'); if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; diff --git a/templates/CRM/Financial/Form/FinancialAccount.tpl b/templates/CRM/Financial/Form/FinancialAccount.tpl index 87026e64e2..a234bf887a 100644 --- a/templates/CRM/Financial/Form/FinancialAccount.tpl +++ b/templates/CRM/Financial/Form/FinancialAccount.tpl @@ -76,6 +76,9 @@ +
+ {include file="CRM/Custom/Form/CustomData.tpl"} +
{/if}
{include file="CRM/common/formButtons.tpl" location="botttom"}
-- 2.25.1