Merge pull request #24049 from pradpnayak/pdfformat
[civicrm-core.git] / CRM / Profile / Form / Dynamic.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 for custom data
20 *
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.
24 *
25 */
26 class CRM_Profile_Form_Dynamic extends CRM_Profile_Form {
27
28 /**
29 * Pre processing work done here.
30 *
31 * @param
32 *
33 */
34 public function preProcess() {
35 if ($this->get('register')) {
36 $this->_mode = CRM_Profile_Form::MODE_REGISTER;
37 }
38 else {
39 $this->_mode = CRM_Profile_Form::MODE_EDIT;
40 }
41
42 if ($this->get('skipPermission')) {
43 $this->_skipPermission = TRUE;
44 }
45
46 // also allow dupes to be updated for edit in my account (CRM-2232)
47 $this->_isUpdateDupe = TRUE;
48
49 parent::preProcess();
50 }
51
52 /**
53 * Build the form object.
54 *
55 */
56 public function buildQuickForm() {
57 $this->addButtons([
58 [
59 'type' => 'upload',
60 'name' => ts('Save'),
61 'isDefault' => TRUE,
62 ],
63 ]);
64
65 // also add a hidden element for to trick drupal
66 $this->addElement('hidden', "edit[civicrm_dummy_field]", "CiviCRM Dummy Field for Drupal");
67 parent::buildQuickForm();
68
69 $this->addFormRule(['CRM_Profile_Form_Dynamic', 'formRule'], $this);
70 }
71
72 /**
73 * Global form rule.
74 *
75 * @param array $fields
76 * The input form values.
77 * @param array $files
78 * The uploaded files if any.
79 * @param CRM_Core_Form $form
80 *
81 *
82 * @return bool|array
83 * true if no errors, else array of errors
84 */
85 public static function formRule($fields, $files, $form) {
86 $errors = [];
87
88 // if no values, return
89 if (empty($fields) || empty($fields['edit'])) {
90 return TRUE;
91 }
92
93 return CRM_Profile_Form::formRule($fields, $files, $form);
94 }
95
96 /**
97 * Process the user submitted custom data values.
98 */
99 public function postProcess() {
100 parent::postProcess();
101 }
102
103 }