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