Merge pull request #21384 from mattwire/groupcontactcache
[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 * 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 */
26class CRM_Profile_Form_Dynamic extends CRM_Profile_Form {
27
28 /**
100fef9d 29 * Pre processing work done here.
6a488035
TO
30 *
31 * @param
32 *
6a488035 33 */
00be9182 34 public function preProcess() {
6a488035
TO
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 /**
fe482240 53 * Build the form object.
6a488035 54 *
6a488035
TO
55 */
56 public function buildQuickForm() {
be2fb01f
CW
57 $this->addButtons([
58 [
c5c263ca
AH
59 'type' => 'upload',
60 'name' => ts('Save'),
61 'isDefault' => TRUE,
be2fb01f
CW
62 ],
63 ]);
6a488035
TO
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
be2fb01f 69 $this->addFormRule(['CRM_Profile_Form_Dynamic', 'formRule'], $this);
6a488035
TO
70 }
71
72 /**
fe482240 73 * Global form rule.
6a488035 74 *
68c9fb83
TO
75 * @param array $fields
76 * The input form values.
77 * @param array $files
78 * The uploaded files if any.
c490a46a 79 * @param CRM_Core_Form $form
77b97be7 80 *
6a488035 81 *
72b3a70c
CW
82 * @return bool|array
83 * true if no errors, else array of errors
6a488035 84 */
00be9182 85 public static function formRule($fields, $files, $form) {
be2fb01f 86 $errors = [];
6a488035
TO
87
88 // if no values, return
8cc574cf 89 if (empty($fields) || empty($fields['edit'])) {
6a488035
TO
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.
6a488035
TO
98 */
99 public function postProcess() {
100 parent::postProcess();
101 }
96025800 102
6a488035 103}