PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.13.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.13.3
5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Settings / FieldConfig.php
matomo / app / core / Settings Last commit date
FieldConfig 3 years ago Measurable 3 years ago Plugin 3 years ago Storage 3 years ago FieldConfig.php 3 years ago Setting.php 3 years ago Settings.php 5 years ago
FieldConfig.php
297 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 *
8 */
9
10 namespace Piwik\Settings;
11 use Piwik\Validators\BaseValidator;
12
13 /**
14 * Lets you configure a form field.
15 *
16 * @api
17 */
18 class FieldConfig
19 {
20 /**
21 * Shows a radio field. To use this field assign it to the `$uiControl` property.
22 */
23 const UI_CONTROL_RADIO = 'radio';
24
25 /**
26 * Shows a text field. To use this field assign it to the `$uiControl` property.
27 */
28 const UI_CONTROL_TEXT = 'text';
29
30 /**
31 * Shows an email text field. To use this field assign it to the `$uiControl` property.
32 */
33 const UI_CONTROL_EMAIL = 'email';
34
35 /**
36 * Shows a URL text field. To use this field assign it to the `$uiControl` property.
37 */
38 const UI_CONTROL_URL = 'url';
39
40 /**
41 * Shows a text area. To use this field assign it to the `$uiControl` property.
42 */
43 const UI_CONTROL_TEXTAREA = 'textarea';
44
45 /**
46 * Shows a checkbox. To use this field assign it to the `$uiControl` property.
47 */
48 const UI_CONTROL_CHECKBOX = 'checkbox';
49
50 /**
51 * Shows a password field. To use this field assign it to the `$uiControl` property.
52 */
53 const UI_CONTROL_PASSWORD = 'password';
54
55 /**
56 * Shows a select field where a user can select multiple values.
57 * The type "Array" is required for this ui control. To use this field assign it to the `$uiControl` property.
58 */
59 const UI_CONTROL_MULTI_SELECT = 'multiselect';
60
61 /**
62 * Shows a select field. To use this field assign it to the `$uiControl` property.
63 */
64 const UI_CONTROL_SINGLE_SELECT = 'select';
65
66 /**
67 * Shows an expandable select field which is useful when each selectable value belongs to a group.
68 * To use this field assign it to the `$uiControl` property.
69 */
70 const UI_CONTROL_SINGLE_EXPANDABLE_SELECT = 'expandable-select';
71
72 /**
73 * Lets a user configure an array of form fields.
74 */
75 const UI_CONTROL_FIELD_ARRAY = 'field-array';
76
77 /**
78 * Lets a user configure two form fields next to each other, and add multiple entries of those two pairs.
79 */
80 const UI_CONTROL_MULTI_TUPLE = 'multituple';
81
82 /**
83 * Generates a hidden form field. To use this field assign it to the `$uiControl` property.
84 */
85 const UI_CONTROL_HIDDEN = 'hidden';
86
87 /**
88 * Expects an integer value. Is usually used when creating a setting.
89 */
90 const TYPE_INT = 'integer';
91
92 /**
93 * Expects a float value. Is usually used when creating a setting.
94 */
95 const TYPE_FLOAT = 'float';
96
97 /**
98 * Expects a string. Is usually used when creating a setting.
99 */
100 const TYPE_STRING = 'string';
101
102 /**
103 * Expects a boolean. Is usually used when creating a setting.
104 */
105 const TYPE_BOOL = 'boolean';
106
107 /**
108 * Expects an array containing multiple values.
109 */
110 const TYPE_ARRAY = 'array';
111
112 /**
113 * Describes what HTML element should be used to manipulate the setting through Piwik's UI.
114 *
115 * See {@link Piwik\Plugin\Settings} for a list of supported control types.
116 *
117 * @var string
118 */
119 public $uiControl = null;
120
121 /**
122 * Defines a custom template file for a UI control. This file should render a UI control and expose the value in a
123 * "formField.value" angular model. For an example see "plugins/CorePluginsAdmin/angularjs/form-field/field-text.html"
124 *
125 * @var string
126 * @deprecated set $customFieldComponent to ['plugin' => 'MyPlugin', 'component' => 'MyComponentAsItIsExported']
127 */
128 public $customUiControlTemplateFile = '';
129
130 /**
131 * Defines a custom Vue component to use for the internal field UI control. This should be an array with two
132 * keys:
133 *
134 * - plugin: the name of the plugin that the UI control exists in.
135 * - name: the name of the export for the component in the plugin's Vue UMD module.
136 *
137 * @var string[]
138 */
139 public $customFieldComponent;
140
141 /**
142 * Name-value mapping of HTML attributes that will be added HTML form control, eg,
143 * `array('size' => 3)`. Attributes will be escaped before outputting.
144 *
145 * @var array
146 */
147 public $uiControlAttributes = array();
148
149 /**
150 * Makes field full width.
151 * Useful for `$field->uiControl = FieldConfig::UI_CONTROL_MULTI_TUPLE;`
152 *
153 * @var bool
154 */
155 public $fullWidth = false;
156
157 /**
158 * The list of all available values for this setting. If null, the setting can have any value.
159 *
160 * If supplied, this field should be an array mapping available values with their prettified
161 * display value. Eg, if set to `array('nb_visits' => 'Visits', 'nb_actions' => 'Actions')`,
162 * the UI will display **Visits** and **Actions**, and when the user selects one, Piwik will
163 * set the setting to **nb_visits** or **nb_actions** respectively.
164 *
165 * The setting value will be validated if this field is set. If the value is not one of the
166 * available values, an error will be triggered.
167 *
168 * _Note: If a custom validator is supplied (see {@link $validate}), the setting value will
169 * not be validated._
170 *
171 * @var null|array
172 */
173 public $availableValues = null;
174
175 /**
176 * Text that will appear above this setting's section in the _Plugin Settings_ admin page.
177 *
178 * @var null|string
179 */
180 public $introduction = null;
181
182 /**
183 * Text that will appear directly underneath the setting title in the _Plugin Settings_ admin
184 * page. If set, should be a short description of the setting.
185 *
186 * @var null|string
187 */
188 public $description = null;
189
190 /**
191 * Text that will appear next to the setting's section in the _Plugin Settings_ admin page. If set,
192 * it should contain information about the setting that is more specific than a general description,
193 * such as the format of the setting value if it has a special format.
194 *
195 * Be sure to escape any user input as HTML can be used here.
196 *
197 * @var null|string
198 */
199 public $inlineHelp = null;
200
201 /**
202 * A closure that prepares the setting value. If supplied, this closure will be executed before
203 * the setting has been validated.
204 *
205 * **Example**
206 *
207 * $setting->prepare = function ($value, Setting $setting) {
208 * return mb_strtolower($value);
209 * }
210 *
211 * @var null|\Closure
212 */
213 public $prepare = null;
214
215 /**
216 * A closure that does some custom validation on the setting before the setting is persisted.
217 *
218 * The closure should take two arguments: the setting value and the {@link Setting} instance being
219 * validated. If the value is found to be invalid, the closure should throw an exception with
220 * a message that describes the error.
221 *
222 * **Example**
223 *
224 * $setting->validate = function ($value, Setting $setting) {
225 * if ($value > 60) {
226 * throw new \Exception('The time limit is not allowed to be greater than 60 minutes.');
227 * }
228 * }
229 *
230 * @var null|\Closure
231 */
232 public $validate = null;
233
234 /**
235 * A closure that transforms the setting value. If supplied, this closure will be executed after
236 * the setting has been validated.
237 *
238 * _Note: If a transform is supplied, the setting's {@link $type} has no effect. This means the
239 * transformation function will be responsible for casting the setting value to the appropriate
240 * data type._
241 *
242 * **Example**
243 *
244 * $setting->transform = function ($value, Setting $setting) {
245 * if ($value > 30) {
246 * $value = 30;
247 * }
248 *
249 * return (int) $value;
250 * }
251 *
252 * @var null|\Closure
253 */
254 public $transform = null;
255
256 /**
257 * This setting's display name, for example, `'Refresh Interval'`.
258 *
259 * Be sure to escape any user input as HTML can be used here.
260 *
261 * @var string
262 */
263 public $title = '';
264
265 /**
266 * Here you can define conditions so that certain form fields will be only shown when a certain condition
267 * is true. This condition is supposed to be evaluated on the client side dynamically. This way you can hide
268 * for example some fields depending on another field. For example if SiteSearch is disabled, fields to enter
269 * site search keywords is not needed anymore and can be disabled.
270 *
271 * For example 'sitesearch', or 'sitesearch && !use_sitesearch_default' where 'sitesearch' and 'use_sitesearch_default'
272 * are both values of fields.
273 *
274 * @var string
275 */
276 public $condition;
277
278 /**
279 * Here you can add one or multiple instances of `Piwik\Validators\BaseValidator` to avoid having to
280 * write the same validators over and over again in {@link $validate}.
281 *
282 * Examples
283 * Want to require a value to be set?
284 * $fieldConfig->validators[] = new Piwik\Validators\NotEmpty();
285 *
286 * Want to require an email?
287 * $fieldConfig->validators[] = new Piwik\Validators\NotEmpty();
288 * $fieldConfig->validators[] = new Piwik\Validators\Email();
289 *
290 * The core comes with a set of various validators that can be used.
291 *
292 * @var BaseValidator[]
293 */
294 public $validators = [];
295
296 }
297