Merge pull request #15875 from civicrm/5.20
[civicrm-core.git] / CRM / Profile / Form / Dynamic.php
CommitLineData
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 *
17 */
18
19/**
20 * This class generates form components for custom data
21 *
22 * It delegates the work to lower level subclasses and integrates the changes
23 * back in. It also uses a lot of functionality with the CRM API's, so any change
24 * made here could potentially affect the API etc. Be careful, be aware, use unit tests.
25 *
26 */
27class CRM_Profile_Form_Dynamic extends CRM_Profile_Form {
28
29 /**
100fef9d 30 * Pre processing work done here.
6a488035
TO
31 *
32 * @param
33 *
6a488035 34 */
00be9182 35 public function preProcess() {
6a488035
TO
36 if ($this->get('register')) {
37 $this->_mode = CRM_Profile_Form::MODE_REGISTER;
38 }
39 else {
40 $this->_mode = CRM_Profile_Form::MODE_EDIT;
41 }
42
43 if ($this->get('skipPermission')) {
44 $this->_skipPermission = TRUE;
45 }
46
47 // also allow dupes to be updated for edit in my account (CRM-2232)
48 $this->_isUpdateDupe = TRUE;
49
50 parent::preProcess();
51 }
52
53 /**
fe482240 54 * Build the form object.
6a488035 55 *
6a488035
TO
56 */
57 public function buildQuickForm() {
be2fb01f
CW
58 $this->addButtons([
59 [
c5c263ca
AH
60 'type' => 'upload',
61 'name' => ts('Save'),
62 'isDefault' => TRUE,
be2fb01f
CW
63 ],
64 ]);
6a488035
TO
65
66 // also add a hidden element for to trick drupal
67 $this->addElement('hidden', "edit[civicrm_dummy_field]", "CiviCRM Dummy Field for Drupal");
68 parent::buildQuickForm();
69
be2fb01f 70 $this->addFormRule(['CRM_Profile_Form_Dynamic', 'formRule'], $this);
6a488035
TO
71 }
72
73 /**
fe482240 74 * Global form rule.
6a488035 75 *
68c9fb83
TO
76 * @param array $fields
77 * The input form values.
78 * @param array $files
79 * The uploaded files if any.
c490a46a 80 * @param CRM_Core_Form $form
77b97be7 81 *
6a488035 82 *
72b3a70c
CW
83 * @return bool|array
84 * true if no errors, else array of errors
6a488035 85 */
00be9182 86 public static function formRule($fields, $files, $form) {
be2fb01f 87 $errors = [];
6a488035
TO
88
89 // if no values, return
8cc574cf 90 if (empty($fields) || empty($fields['edit'])) {
6a488035
TO
91 return TRUE;
92 }
93
94 return CRM_Profile_Form::formRule($fields, $files, $form);
95 }
96
97 /**
98 * Process the user submitted custom data values.
6a488035
TO
99 */
100 public function postProcess() {
101 parent::postProcess();
102 }
96025800 103
6a488035 104}