Switch contribution to use same error handling
[civicrm-core.git] / CRM / Custom / Form / CustomDataByType.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This form is intended to replace the overloading of many forms to generate a snippet for custom data.
20 */
21 class CRM_Custom_Form_CustomDataByType extends CRM_Core_Form {
22
23 /**
24 * Contact ID associated with the Custom Data
25 *
26 * @var int
27 */
28 public $_contactID = NULL;
29
30 /**
31 * Preprocess function.
32 */
33 public function preProcess() {
34
35 $this->_type = $this->_cdType = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject, TRUE);
36 $this->_subType = CRM_Utils_Request::retrieve('subType', 'String');
37 $this->_subName = CRM_Utils_Request::retrieve('subName', 'String');
38 $this->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive');
39 $this->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive');
40 $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive');
41 $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive');
42 $this->_onlySubtype = CRM_Utils_Request::retrieve('onlySubtype', 'Boolean');
43 $this->_action = CRM_Utils_Request::retrieve('action', 'Alphanumeric');
44 $this->assign('cdType', FALSE);
45 $this->assign('cgCount', $this->_groupCount);
46
47 $contactTypes = CRM_Contact_BAO_ContactType::contactTypeInfo();
48 if (array_key_exists($this->_type, $contactTypes)) {
49 $this->assign('contactId', $this->_entityId);
50 }
51 if (!is_array($this->_subType) && strstr($this->_subType, CRM_Core_DAO::VALUE_SEPARATOR)) {
52 $this->_subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($this->_subType, CRM_Core_DAO::VALUE_SEPARATOR));
53 }
54 CRM_Custom_Form_CustomData::setGroupTree($this, $this->_subType, $this->_groupID, $this->_onlySubtype);
55
56 $this->assign('suppressForm', TRUE);
57 $this->controller->_generateQFKey = FALSE;
58 }
59
60 /**
61 * Set defaults.
62 *
63 * @return array
64 */
65 public function setDefaultValues() {
66 $defaults = [];
67 CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, FALSE, FALSE, $this->get('action'));
68 return $defaults;
69 }
70
71 /**
72 * Build quick form.
73 */
74 public function buildQuickForm() {
75 $this->addElement('hidden', 'hidden_custom', 1);
76 $this->addElement('hidden', "hidden_custom_group_count[{$this->_groupID}]", $this->_groupCount);
77 CRM_Core_BAO_CustomGroup::buildQuickForm($this, $this->_groupTree);
78 }
79
80 }