Merge pull request #23495 from eileenmcnaughton/import_unused
[civicrm-core.git] / CRM / UF / Form / AbstractPreview.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 class generates form components
20 * for previewing Civicrm Profile Group
21 *
22 */
23 class CRM_UF_Form_AbstractPreview extends CRM_Core_Form {
24
25 /**
26 * The fields needed to build this form.
27 *
28 * @var array
29 */
30 public $_fields;
31
32 /**
33 * Set the profile/field structure for this form
34 *
35 * @param array $fields
36 * List of fields per CRM_Core_BAO_UFGroup::formatUFFields or CRM_Core_BAO_UFGroup::getFields.
37 * @param bool $isSingleField
38 * @param bool $flag
39 */
40 public function setProfile($fields, $isSingleField = FALSE, $flag = FALSE) {
41 if ($isSingleField) {
42 $this->assign('previewField', $isSingleField);
43 }
44
45 if ($flag) {
46 $this->assign('viewOnly', FALSE);
47 }
48 else {
49 $this->assign('viewOnly', TRUE);
50 }
51
52 $this->set('fieldId', NULL);
53 $this->assign("fields", $fields);
54 $this->_fields = $fields;
55 }
56
57 /**
58 * Set the default form values.
59 *
60 *
61 * @return array
62 * the default array reference
63 */
64 public function setDefaultValues() {
65 $defaults = [];
66 foreach ($this->_fields as $name => $field) {
67 if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) {
68 CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
69 }
70 }
71
72 //set default for country.
73 CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults);
74
75 return $defaults;
76 }
77
78 /**
79 * Build the form object.
80 *
81 * @return void
82 */
83 public function buildQuickForm() {
84 foreach ($this->_fields as $name => $field) {
85 if (empty($field['is_view'])) {
86 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
87 }
88 }
89 }
90
91 /**
92 * Use the form name to create the tpl file name.
93 *
94 * @return string
95 */
96
97 /**
98 * @return string
99 */
100 public function getTemplateFileName() {
101 return 'CRM/UF/Form/Preview.tpl';
102 }
103
104 }