From 448ef7f3ebfe482e6ba911bf33b37f1e7bbd450b Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 15 Mar 2020 11:05:25 +1300 Subject: [PATCH] [REF] cleanup financial type form - remove complex inheritence Inheriting from 2 intermediary forms adds complexity with little benefit. Since we have the entityFormTrait this increases use of that --- CRM/Financial/Form/FinancialType.php | 31 +++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/CRM/Financial/Form/FinancialType.php b/CRM/Financial/Form/FinancialType.php index 2e5e1ea46b..9dce6892ac 100644 --- a/CRM/Financial/Form/FinancialType.php +++ b/CRM/Financial/Form/FinancialType.php @@ -18,10 +18,12 @@ /** * This class generates form components for Financial Type */ -class CRM_Financial_Form_FinancialType extends CRM_Contribute_Form { +class CRM_Financial_Form_FinancialType extends CRM_Core_Form { use CRM_Core_Form_EntityFormTrait; + protected $_BAOName = 'CRM_Financial_BAO_FinancialType'; + /** * Fields for the entity to be assigned to the template. * @@ -98,9 +100,11 @@ class CRM_Financial_Form_FinancialType extends CRM_Contribute_Form { /** * Build the form object. + * + * @throws \CRM_Core_Exception */ public function buildQuickForm() { - self::buildQuickEntityForm(); + $this->buildQuickEntityForm(); if ($this->_action & CRM_Core_Action::DELETE) { return; } @@ -114,6 +118,8 @@ class CRM_Financial_Form_FinancialType extends CRM_Contribute_Form { /** * Process the form submission. + * + * @throws \CiviCRM_API3_Exception */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { @@ -148,11 +154,11 @@ class CRM_Financial_Form_FinancialType extends CRM_Contribute_Form { 1 => $params['name'], ]; $financialAccounts = civicrm_api3('EntityFinancialAccount', 'get', [ - 'return' => ["financial_account_id.name"], - 'entity_table' => "civicrm_financial_type", + 'return' => ['financial_account_id.name'], + 'entity_table' => 'civicrm_financial_type', 'entity_id' => $financialType['id'], 'options' => ['sort' => "id"], - 'account_relationship' => ['!=' => "Income Account is"], + 'account_relationship' => ['!=' => 'Income Account is'], ]); if (!empty($financialAccounts['values'])) { foreach ($financialAccounts['values'] as $financialAccount) { @@ -171,4 +177,19 @@ class CRM_Financial_Form_FinancialType extends CRM_Contribute_Form { } } + /** + * Set default values for the form. MobileProvider that in edit/view mode + * the default values are retrieved from the database + * + * @return array + */ + public function setDefaultValues() { + $defaults = $this->getEntityDefaults(); + + if ($this->_action & CRM_Core_Action::ADD) { + $defaults['is_active'] = 1; + } + return $defaults; + } + } -- 2.25.1