Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-08-04-22-25-32
[civicrm-core.git] / CRM / Profile / Form / Dynamic.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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 * @access public
54 *
55 */
56 function preProcess() {
57 if ($this->get('register')) {
58 $this->_mode = CRM_Profile_Form::MODE_REGISTER;
59 }
60 else {
61 $this->_mode = CRM_Profile_Form::MODE_EDIT;
62 }
63
64 if ($this->get('skipPermission')) {
65 $this->_skipPermission = TRUE;
66 }
67
68 // also allow dupes to be updated for edit in my account (CRM-2232)
69 $this->_isUpdateDupe = TRUE;
70
71 parent::preProcess();
72 }
73
74 /**
75 * Function to actually build the form
76 *
77 * @return void
78 * @access public
79 */
80 public function buildQuickForm() {
81 $this->addButtons(array(
82 array(
83 'type' => 'upload',
84 'name' => ts('Save'),
85 'isDefault' => TRUE,
86 ),
87 )
88 );
89
90 // also add a hidden element for to trick drupal
91 $this->addElement('hidden', "edit[civicrm_dummy_field]", "CiviCRM Dummy Field for Drupal");
92 parent::buildQuickForm();
93
94 $this->addFormRule(array('CRM_Profile_Form_Dynamic', 'formRule'), $this);
95 }
96
97 /**
98 * global form rule
99 *
100 * @param array $fields the input form values
101 * @param array $files the uploaded files if any
102 * @param object $form
103 *
104 * @internal param array $options additional user data
105 *
106 * @return true if no errors, else array of errors
107 * @access public
108 * @static
109 */
110 static function formRule($fields, $files, $form) {
111 $errors = array();
112
113 // if no values, return
114 if (empty($fields) || empty($fields['edit'])) {
115 return TRUE;
116 }
117
118 return CRM_Profile_Form::formRule($fields, $files, $form);
119 }
120
121 /**
122 * Process the user submitted custom data values.
123 *
124 * @access public
125 *
126 * @return void
127 */
128 public function postProcess() {
129 parent::postProcess();
130 }
131 }
132