Merge pull request #7047 from johanv/CRM-17430-dont_change_domain_version_1st_attempt
[civicrm-core.git] / CRM / Profile / Form / Dynamic.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2016
32 * $Id$
33 *
34 */
35
36 /**
37 * This class generates form components for custom data
38 *
39 * It delegates the work to lower level subclasses and integrates the changes
40 * back in. It also uses a lot of functionality with the CRM API's, so any change
41 * made here could potentially affect the API etc. Be careful, be aware, use unit tests.
42 *
43 */
44 class CRM_Profile_Form_Dynamic extends CRM_Profile_Form {
45
46 /**
47 * Pre processing work done here.
48 *
49 * @param
50 *
51 * @return void
52 */
53 public function preProcess() {
54 if ($this->get('register')) {
55 $this->_mode = CRM_Profile_Form::MODE_REGISTER;
56 }
57 else {
58 $this->_mode = CRM_Profile_Form::MODE_EDIT;
59 }
60
61 if ($this->get('skipPermission')) {
62 $this->_skipPermission = TRUE;
63 }
64
65 // also allow dupes to be updated for edit in my account (CRM-2232)
66 $this->_isUpdateDupe = TRUE;
67
68 parent::preProcess();
69 }
70
71 /**
72 * Build the form object.
73 *
74 * @return void
75 */
76 public function buildQuickForm() {
77 $this->addButtons(array(
78 array(
79 'type' => 'upload',
80 'name' => ts('Save'),
81 'isDefault' => TRUE,
82 ),
83 ));
84
85 // also add a hidden element for to trick drupal
86 $this->addElement('hidden', "edit[civicrm_dummy_field]", "CiviCRM Dummy Field for Drupal");
87 parent::buildQuickForm();
88
89 $this->addFormRule(array('CRM_Profile_Form_Dynamic', 'formRule'), $this);
90 }
91
92 /**
93 * Global form rule.
94 *
95 * @param array $fields
96 * The input form values.
97 * @param array $files
98 * The uploaded files if any.
99 * @param CRM_Core_Form $form
100 *
101 *
102 * @return bool|array
103 * true if no errors, else array of errors
104 */
105 public static function formRule($fields, $files, $form) {
106 $errors = array();
107
108 // if no values, return
109 if (empty($fields) || empty($fields['edit'])) {
110 return TRUE;
111 }
112
113 return CRM_Profile_Form::formRule($fields, $files, $form);
114 }
115
116 /**
117 * Process the user submitted custom data values.
118 *
119 *
120 * @return void
121 */
122 public function postProcess() {
123 parent::postProcess();
124 }
125
126 }