Commit | Line | Data |
---|---|---|
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 | * $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 | /** | |
fe482240 | 28 | * The fields needed to build this form. |
6a488035 TO |
29 | * |
30 | * @var array | |
31 | */ | |
32 | public $_fields; | |
33 | ||
34 | /** | |
35 | * Set the profile/field structure for this form | |
36 | * | |
5ce1712d TO |
37 | * @param array $fields |
38 | * List of fields per CRM_Core_BAO_UFGroup::formatUFFields or CRM_Core_BAO_UFGroup::getFields. | |
6a488035 TO |
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 | /** | |
fe482240 | 60 | * Set the default form values. |
6a488035 | 61 | * |
6a488035 | 62 | * |
a6c01b45 CW |
63 | * @return array |
64 | * the default array reference | |
6a488035 | 65 | */ |
00be9182 | 66 | public function setDefaultValues() { |
be2fb01f | 67 | $defaults = []; |
6a488035 TO |
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 | } | |
6a488035 TO |
72 | } |
73 | ||
74 | //set default for country. | |
75 | CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults); | |
76 | ||
6a488035 TO |
77 | return $defaults; |
78 | } | |
79 | ||
80 | /** | |
fe482240 | 81 | * Build the form object. |
6a488035 TO |
82 | * |
83 | * @return void | |
6a488035 TO |
84 | */ |
85 | public function buildQuickForm() { | |
86 | foreach ($this->_fields as $name => $field) { | |
a7488080 | 87 | if (empty($field['is_view'])) { |
6a488035 TO |
88 | CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE); |
89 | } | |
90 | } | |
91 | } | |
92 | ||
624e56fa | 93 | /** |
fe482240 | 94 | * Use the form name to create the tpl file name. |
624e56fa EM |
95 | * |
96 | * @return string | |
624e56fa | 97 | */ |
3655bea4 | 98 | |
624e56fa EM |
99 | /** |
100 | * @return string | |
101 | */ | |
6a488035 TO |
102 | public function getTemplateFileName() { |
103 | return 'CRM/UF/Form/Preview.tpl'; | |
104 | } | |
96025800 | 105 | |
6a488035 | 106 | } |