3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class generates form components for previewing custom data
21 * It delegates the work to lower level subclasses and integrates the changes
22 * back in. It also uses a lot of functionality with the CRM API's, so any change
23 * made here could potentially affect the API etc. Be careful, be aware, use unit tests.
26 class CRM_Custom_Form_Preview
extends CRM_Core_Form
{
29 * The group tree data.
33 protected $_groupTree;
36 * Pre processing work done here.
38 * gets session variables for group or field id
42 public function preProcess() {
43 // get the controller vars
44 $this->_groupId
= $this->get('groupId');
45 $this->_fieldId
= $this->get('fieldId');
46 if ($this->_fieldId
) {
49 $params = ['id' => $this->_fieldId
];
50 $fieldDAO = new CRM_Core_DAO_CustomField();
51 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults);
53 if (!empty($defaults['is_view'])) {
54 CRM_Core_Error
::statusBounce(ts('This field is view only so it will not display on edit form.'));
56 elseif (empty($defaults['is_active'])) {
57 CRM_Core_Error
::statusBounce(ts('This field is inactive so it will not display on edit form.'));
61 $groupTree[$this->_groupId
]['id'] = 0;
62 $groupTree[$this->_groupId
]['fields'] = [];
63 $groupTree[$this->_groupId
]['fields'][$this->_fieldId
] = $defaults;
64 $this->_groupTree
= CRM_Core_BAO_CustomGroup
::formatGroupTree($groupTree, 1, $this);
65 $this->assign('preview_type', 'field');
68 $groupTree = CRM_Core_BAO_CustomGroup
::getGroupDetail($this->_groupId
);
69 $this->_groupTree
= CRM_Core_BAO_CustomGroup
::formatGroupTree($groupTree, TRUE, $this);
70 $this->assign('preview_type', 'group');
75 * Set the default form values.
78 * the default array reference
80 public function setDefaultValues() {
83 CRM_Core_BAO_CustomGroup
::setDefaults($this->_groupTree
, $defaults, FALSE, FALSE);
89 * Build the form object.
93 public function buildQuickForm() {
94 if (is_array($this->_groupTree
) && !empty($this->_groupTree
[$this->_groupId
])) {
95 foreach ($this->_groupTree
[$this->_groupId
]['fields'] as & $field) {
96 //add the form elements
97 CRM_Core_BAO_CustomField
::addQuickFormElement($this, $field['element_name'], $field['id'], CRM_Utils_Array
::value('is_required', $field));
100 $this->assign('groupTree', $this->_groupTree
);
105 'name' => ts('Done with Preview'),