1 | <?php |
||
8 | class PodsField { |
||
9 | |||
10 | /** |
||
11 | * Whether this field is running under 1.x deprecated forms |
||
12 | * |
||
13 | * @var bool |
||
14 | * @since 2.0 |
||
15 | */ |
||
16 | public static $deprecated = false; |
||
17 | |||
18 | /** |
||
19 | * Field Type Identifier |
||
20 | * |
||
21 | * @var string |
||
22 | * @since 2.0 |
||
23 | */ |
||
24 | public static $type = 'text'; |
||
25 | |||
26 | /** |
||
27 | * Field Type Label |
||
28 | * |
||
29 | * @var string |
||
30 | * @since 2.0 |
||
31 | */ |
||
32 | public static $label = 'Unknown'; |
||
33 | |||
34 | /** |
||
35 | * Field Type Preparation |
||
36 | * |
||
37 | * @var string |
||
38 | * @since 2.0 |
||
39 | */ |
||
40 | public static $prepare = '%s'; |
||
41 | |||
42 | /** |
||
43 | * Pod Types supported on (true for all, false for none, or give array of specific types supported) |
||
44 | * |
||
45 | * @var array|bool |
||
46 | * @since 2.1 |
||
47 | */ |
||
48 | public static $pod_types = true; |
||
49 | |||
50 | /** |
||
51 | * API caching for fields that need it during validate/save |
||
52 | * |
||
53 | * @var \PodsAPI |
||
54 | * @since 2.3 |
||
55 | */ |
||
56 | private static $api = false; |
||
|
|||
57 | |||
58 | /** |
||
59 | * Do things like register/enqueue scripts and stylesheets |
||
60 | * |
||
61 | * @since 2.0 |
||
62 | */ |
||
63 | public function __construct() { |
||
68 | |||
69 | /** |
||
70 | * Add options and set defaults for field type, shows in admin area |
||
71 | * |
||
72 | * @return array $options |
||
73 | * |
||
74 | * @since 2.0 |
||
75 | * @see PodsField::ui_options |
||
76 | */ |
||
77 | public function options() { |
||
122 | |||
123 | /** |
||
124 | * Options for the Admin area, defaults to $this->options() |
||
125 | * |
||
126 | * @return array $options |
||
127 | * |
||
128 | * @since 2.0 |
||
129 | * @see PodsField::options |
||
130 | */ |
||
131 | public function ui_options() { |
||
136 | |||
137 | /** |
||
138 | * Define the current field's schema for DB table storage |
||
139 | * |
||
140 | * @param array|null $options |
||
141 | * |
||
142 | * @return string |
||
143 | * |
||
144 | * @since 2.0 |
||
145 | */ |
||
146 | public function schema( $options = null ) { |
||
153 | |||
154 | /** |
||
155 | * Define the current field's preparation for sprintf |
||
156 | * |
||
157 | * @param array|null $options |
||
158 | * |
||
159 | * @return string |
||
160 | * |
||
161 | * @since 2.0 |
||
162 | */ |
||
163 | public function prepare( $options = null ) { |
||
170 | |||
171 | /** |
||
172 | * Change the value of the field |
||
173 | * |
||
174 | * @param mixed|null $value |
||
175 | * @param string|null $name |
||
176 | * @param array|null $options |
||
177 | * @param array|null $pod |
||
178 | * @param int|null $id |
||
179 | * |
||
180 | * @return mixed|null|string |
||
181 | * |
||
182 | * @since 2.3 |
||
183 | */ |
||
184 | public function value( $value = null, $name = null, $options = null, $pod = null, $id = null ) { |
||
189 | |||
190 | /** |
||
191 | * Change the way the value of the field is displayed with Pods::get |
||
192 | * |
||
193 | * @param mixed|null $value |
||
194 | * @param string|null $name |
||
195 | * @param array|null $options |
||
196 | * @param array|null $pod |
||
197 | * @param int|null $id |
||
198 | * |
||
199 | * @return mixed|null|string |
||
200 | * |
||
201 | * @since 2.0 |
||
202 | */ |
||
203 | public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) { |
||
208 | |||
209 | /** |
||
210 | * Customize output of the form field |
||
211 | * |
||
212 | * @param string $name |
||
213 | * @param mixed|null $value |
||
214 | * @param array|null $options |
||
215 | * @param array|null $pod |
||
216 | * @param int|null $id |
||
217 | * |
||
218 | * @since 2.0 |
||
219 | */ |
||
220 | public function input( $name, $value = null, $options = null, $pod = null, $id = null ) { |
||
245 | |||
246 | /** |
||
247 | * Render input script for Pods DFV |
||
248 | * |
||
249 | * @param array|object $args { |
||
250 | * Field information arguments. |
||
251 | * |
||
252 | * @type string $name Field name |
||
253 | * @type string $type Field type |
||
254 | * @type array $options Field options |
||
255 | * @type mixed $value Current value |
||
256 | * @type array $pod Pod information |
||
257 | * @type int|string $id Current item ID |
||
258 | * } |
||
259 | */ |
||
260 | public function render_input_script( $args ) { |
||
274 | |||
275 | /** |
||
276 | * Build field data for Pods DFV |
||
277 | * |
||
278 | * @param object $args { |
||
279 | * Field information arguments. |
||
280 | * |
||
281 | * @type string $name Field name |
||
282 | * @type string $type Pod field type |
||
283 | * @type string $form_field_type HTML field type |
||
284 | * @type array $options Field options |
||
285 | * @type mixed $value Current value |
||
286 | * @type array $pod Pod information |
||
287 | * @type int|string $id Current item ID |
||
288 | * } |
||
289 | * |
||
290 | * @return array |
||
291 | */ |
||
292 | public function build_dfv_field_data( $args ) { |
||
339 | |||
340 | /** |
||
341 | * Build field options and handle any validation/customization for Pods DFV |
||
342 | * |
||
343 | * @param array $options |
||
344 | * @param object $args { |
||
345 | * Field information arguments. |
||
346 | * |
||
347 | * @type string $name Field name |
||
348 | * @type string $type Field type |
||
349 | * @type array $options Field options |
||
350 | * @type mixed $value Current value |
||
351 | * @type array $pod Pod information |
||
352 | * @type int|string $id Current item ID |
||
353 | * } |
||
354 | * |
||
355 | * @return array |
||
356 | */ |
||
357 | public function build_dfv_field_options( $options, $args ) { |
||
362 | |||
363 | /** |
||
364 | * Build field HTML attributes for Pods DFV. |
||
365 | * |
||
366 | * @param array $attributes Default HTML attributes from field and PodsForm::merge_attributes. |
||
367 | * @param object $args { |
||
368 | * Field information arguments. |
||
369 | * |
||
370 | * @type string $name Field name |
||
371 | * @type string $type Field type |
||
372 | * @type array $options Field options |
||
373 | * @type mixed $value Current value |
||
374 | * @type array $pod Pod information |
||
375 | * @type int|string $id Current item ID |
||
376 | * } |
||
377 | * |
||
378 | * @return array |
||
379 | */ |
||
380 | public function build_dfv_field_attributes( $attributes, $args ) { |
||
385 | |||
386 | /** |
||
387 | * Build field config for Pods DFV using field options. |
||
388 | * |
||
389 | * This is for customizing the options and adding output-specific config values. |
||
390 | * |
||
391 | * @param object $args { |
||
392 | * Field information arguments. |
||
393 | * |
||
394 | * @type string $name Field name |
||
395 | * @type string $type Field type |
||
396 | * @type array $options Field options |
||
397 | * @type mixed $value Current value |
||
398 | * @type array $pod Pod information |
||
399 | * @type int|string $id Current item ID |
||
400 | * } |
||
401 | * |
||
402 | * @return array |
||
403 | */ |
||
404 | public function build_dfv_field_config( $args ) { |
||
415 | |||
416 | /** |
||
417 | * Build array of item data for Pods DFV |
||
418 | * |
||
419 | * @param object $args { |
||
420 | * Field information arguments. |
||
421 | * |
||
422 | * @type string $name Field name |
||
423 | * @type string $type Field type |
||
424 | * @type array $options Field options |
||
425 | * @type mixed $value Current value |
||
426 | * @type array $pod Pod information |
||
427 | * @type int|string $id Current item ID |
||
428 | * } |
||
429 | * |
||
430 | * @return array |
||
431 | */ |
||
432 | public function build_dfv_field_item_data( $args ) { |
||
443 | |||
444 | /** |
||
445 | * Get the data from the field |
||
446 | * |
||
447 | * @param string $name The name of the field |
||
448 | * @param string|array|null $value The value of the field |
||
449 | * @param array|null $options |
||
450 | * @param array|null $pod |
||
451 | * @param int|null $id |
||
452 | * @param boolean $in_form |
||
453 | * |
||
454 | * @return array Array of possible field data |
||
455 | * |
||
456 | * @since 2.0 |
||
457 | */ |
||
458 | public function data( $name, $value = null, $options = null, $pod = null, $id = null, $in_form = true ) { |
||
463 | |||
464 | /** |
||
465 | * Build regex necessary for JS validation |
||
466 | * |
||
467 | * @param mixed|null $value |
||
468 | * @param string|null $name |
||
469 | * @param array|null $options |
||
470 | * @param string|null $pod |
||
471 | * @param int|null $id |
||
472 | * |
||
473 | * @return bool |
||
474 | * |
||
475 | * @since 2.0 |
||
476 | */ |
||
477 | public function regex( $value = null, $name = null, $options = null, $pod = null, $id = null ) { |
||
482 | |||
483 | /** |
||
484 | * Validate a value before it's saved |
||
485 | * |
||
486 | * @param mixed $value |
||
487 | * @param string|null $name |
||
488 | * @param array|null $options |
||
489 | * @param array|null $fields |
||
490 | * @param array|null $pod |
||
491 | * @param int|null $id |
||
492 | * @param array|null $params |
||
493 | * |
||
494 | * @return bool |
||
495 | * |
||
496 | * @since 2.0 |
||
497 | */ |
||
498 | public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) { |
||
503 | |||
504 | /** |
||
505 | * Change the value or perform actions after validation but before saving to the DB |
||
506 | * |
||
507 | * @param mixed $value |
||
508 | * @param int|null $id |
||
509 | * @param string|null $name |
||
510 | * @param array|null $options |
||
511 | * @param array|null $fields |
||
512 | * @param array|null $pod |
||
513 | * @param object|null $params |
||
514 | * |
||
515 | * @return mixed |
||
516 | * |
||
517 | * @since 2.0 |
||
518 | */ |
||
519 | public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { |
||
524 | |||
525 | /** |
||
526 | * Save the value to the DB |
||
527 | * |
||
528 | * @param mixed $value |
||
529 | * @param int|null $id |
||
530 | * @param string|null $name |
||
531 | * @param array|null $options |
||
532 | * @param array|null $fields |
||
533 | * @param array|null $pod |
||
534 | * @param object|null $params |
||
535 | * |
||
536 | * @return bool|null Whether the value was saved, returning null means no save needed to occur |
||
537 | * |
||
538 | * @since 2.3 |
||
539 | */ |
||
540 | public function save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { |
||
545 | |||
546 | /** |
||
547 | * Perform actions after saving to the DB |
||
548 | * |
||
549 | * @param mixed $value |
||
550 | * @param int|null $id |
||
551 | * @param string|null $name |
||
552 | * @param array|null $options |
||
553 | * @param array|null $fields |
||
554 | * @param array|null $pod |
||
555 | * @param object|null $params |
||
556 | * |
||
557 | * @since 2.0 |
||
558 | */ |
||
559 | public function post_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { |
||
564 | |||
565 | /** |
||
566 | * Perform actions before deleting from the DB |
||
567 | * |
||
568 | * @param int|null $id |
||
569 | * @param string|null $name |
||
570 | * @param array|null $options |
||
571 | * @param string|null $pod |
||
572 | * |
||
573 | * @since 2.0 |
||
574 | */ |
||
575 | public function pre_delete( $id = null, $name = null, $options = null, $pod = null ) { |
||
580 | |||
581 | /** |
||
582 | * Delete the value from the DB |
||
583 | * |
||
584 | * @param int|null $id |
||
585 | * @param string|null $name |
||
586 | * @param array|null $options |
||
587 | * @param array|null $pod |
||
588 | * |
||
589 | * @since 2.3 |
||
590 | */ |
||
591 | public function delete( $id = null, $name = null, $options = null, $pod = null ) { |
||
596 | |||
597 | /** |
||
598 | * Perform actions after deleting from the DB |
||
599 | * |
||
600 | * @param int|null $id |
||
601 | * @param string|null $name |
||
602 | * @param array|null $options |
||
603 | * @param array|null $pod |
||
604 | * |
||
605 | * @since 2.0 |
||
606 | */ |
||
607 | public function post_delete( $id = null, $name = null, $options = null, $pod = null ) { |
||
612 | |||
613 | /** |
||
614 | * Customize the Pods UI manage table column output |
||
615 | * |
||
616 | * @param int $id |
||
617 | * @param mixed $value |
||
618 | * @param string|null $name |
||
619 | * @param array|null $options |
||
620 | * @param array|null $fields |
||
621 | * @param array|null $pod |
||
622 | * |
||
623 | * @return string Value to be shown in the UI |
||
624 | * |
||
625 | * @since 2.0 |
||
626 | */ |
||
627 | public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) { |
||
632 | |||
633 | /** |
||
634 | * Placeholder function to allow var_export() use with classes |
||
635 | * |
||
636 | * @param array $properties |
||
637 | * |
||
638 | * @return object|void |
||
639 | */ |
||
640 | public static function __set_state( $properties ) { |
||
645 | |||
646 | } |
||
647 |
This check marks private properties in classes that are never used. Those properties can be removed.