Merge in 5.20
[civicrm-core.git] / CRM / Contribute / Form.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
95cdcc0f 19 * This class generates form components generic to Contribution admin.
6a488035 20 */
81b69437 21class CRM_Contribute_Form extends CRM_Admin_Form {
6a488035
TO
22
23 /**
95cdcc0f 24 * Set default values for the form.
6a488035 25 *
81b69437 26 * @return array
6a488035 27 */
00be9182 28 public function setDefaultValues() {
be2fb01f 29 $defaults = [];
6a488035
TO
30
31 if (isset($this->_id)) {
be2fb01f 32 $params = ['id' => $this->_id];
481a74f4 33 if (!empty($this->_BAOName)) {
0e6e8724
DL
34 $baoName = $this->_BAOName;
35 $baoName::retrieve($params, $defaults);
6a488035
TO
36 }
37 }
8cc574cf 38 if ($this->_action == CRM_Core_Action::DELETE && !empty($defaults['name'])) {
6a488035
TO
39 $this->assign('delName', $defaults['name']);
40 }
41 elseif ($this->_action == CRM_Core_Action::ADD) {
42 $condition = " AND is_default = 1";
874c9be7 43 $values = CRM_Core_OptionGroup::values('financial_account_type', FALSE, FALSE, FALSE, $condition);
6a488035
TO
44 $defaults['financial_account_type_id'] = array_keys($values);
45 $defaults['is_active'] = 1;
46
47 }
48 elseif ($this->_action & CRM_Core_Action::UPDATE) {
8cc574cf 49 if (!empty($defaults['contact_id']) || !empty($defaults['created_id'])) {
0d8afee2 50 $contactID = !empty($defaults['created_id']) ? $defaults['created_id'] : $defaults['contact_id'];
6a488035
TO
51 $this->assign('created_id', $contactID);
52 $this->assign('organisationId', $contactID);
53 }
54
55 if ($parentId = CRM_Utils_Array::value('parent_id', $defaults)) {
56 $this->assign('parentId', $parentId);
57 }
0e6e8724 58 }
6a488035
TO
59 return $defaults;
60 }
61
6a488035 62}