PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / trunk
Pods – Custom Content Types and Fields vtrunk
trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / src / Pods / Admin / Config / Field.php
pods / src / Pods / Admin / Config Last commit date
Base.php 4 months ago Field.php 4 months ago Group.php 4 months ago Pod.php 4 months ago
Field.php
808 lines
1 <?php
2
3 namespace Pods\Admin\Config;
4
5 // Don't load directly.
6 if ( ! defined( 'ABSPATH' ) ) {
7 die( '-1' );
8 }
9
10 use Pods\WP\Meta;
11 use PodsForm;
12
13 /**
14 * Field configuration class.
15 *
16 * @since 2.8.0
17 */
18 class Field extends Base {
19
20 /**
21 * Get list of tabs for the Field object.
22 *
23 * @since 2.8.0
24 *
25 * @param \Pods\Whatsit\Pod $pod The pod object.
26 *
27 * @return array List of tabs for the Field object.
28 */
29 public function get_tabs( \Pods\Whatsit\Pod $pod ) {
30 $repeatable_field_types = PodsForm::repeatable_field_types();
31
32 $core_tabs = [
33 'basic' => __( 'Field Details', 'pods' ),
34 ];
35
36 $field_types = PodsForm::field_types();
37
38 foreach ( $field_types as $type => $field_type_data ) {
39 $core_tabs[ 'additional-field-' . $type ] = [
40 'name' => 'additional-field-' . $type,
41 /* translators: %s: Field type label. */
42 'label' => sprintf( _x( '%s Options', 'Field type options', 'pods' ), $field_type_data['label'] ),
43 'depends-on' => [
44 'type' => $type,
45 ],
46 ];
47 }
48
49 $core_tabs['repeatable'] = [
50 'name' => 'repeatable',
51 'label' => __( 'Repeatable', 'pods' ),
52 'depends-on' => [
53 'type' => $repeatable_field_types,
54 ],
55 ];
56
57 $core_tabs['advanced'] = __( 'Advanced', 'pods' );
58 $core_tabs['conditional-logic'] = __( 'Conditional Logic', 'pods' );
59
60 // Only include kitchen sink if dev mode on and not running Codecept tests.
61 if ( pods_developer() && ! function_exists( 'codecept_debug' ) ) {
62 $core_tabs['kitchen-sink'] = __( 'Kitchen Sink (temp)', 'pods' );
63 }
64
65 $pod_type = $pod['type'];
66 $pod_name = $pod['name'];
67
68 $tabs = $core_tabs;
69
70 /**
71 * Filter the Pod Field option tabs for a specific pod type and name.
72 *
73 * @since 2.8.0
74 *
75 * @param array $core_tabs Tabs to set.
76 * @param \Pods\Whatsit\Pod $pod Current Pods object.
77 */
78 $tabs = (array) apply_filters( "pods_admin_setup_edit_field_tabs_{$pod_type}_{$pod_name}", $tabs, $pod );
79
80 /**
81 * Filter the Pod Field option tabs for a specific pod type.
82 *
83 * @since 2.8.0
84 *
85 * @param array $tabs Tabs to set.
86 * @param \Pods\Whatsit\Pod $pod Current Pods object.
87 */
88 $tabs = (array) apply_filters( "pods_admin_setup_edit_field_tabs_{$pod_type}", $tabs, $pod );
89
90 /**
91 * Filter the Pod Field option tabs.
92 *
93 * @since 2.8.0
94 *
95 * @param array $tabs Tabs to set.
96 * @param \Pods\Whatsit\Pod $pod Current Pods object.
97 */
98 $tabs = (array) apply_filters( 'pods_admin_setup_edit_field_tabs', $tabs, $pod );
99
100 // Sort and then enforce the core tabs to be in front.
101 uksort( $tabs, 'strnatcmp' );
102
103 $tabs = array_merge( $core_tabs, $tabs );
104
105 return $tabs;
106 }
107
108 /**
109 * Get list of fields for the Field object.
110 *
111 * @since 2.8.0
112 *
113 * @param \Pods\Whatsit\Pod $pod The pod object.
114 * @param array $tabs The list of tabs for the pod object.
115 *
116 * @return array List of fields for the Field object.
117 */
118 public function get_fields( \Pods\Whatsit\Pod $pod, array $tabs ) {
119 $field_types = PodsForm::field_types();
120 $tableless_field_types = PodsForm::tableless_field_types();
121 $repeatable_field_types = PodsForm::repeatable_field_types();
122 $separator_excluded_field_types = PodsForm::separator_excluded_field_types();
123 $layout_non_input_field_types = PodsForm::layout_field_types() + PodsForm::non_input_field_types();
124
125 // Remove repeatable fields custom separator options.
126 $serial_repeatable_field_types = array_values( array_diff( $repeatable_field_types, $separator_excluded_field_types ) );
127
128 $options = [];
129
130 $options['basic'] = [
131 'label' => [
132 'name' => 'label',
133 'label' => __( 'Label', 'pods' ),
134 'type' => 'text',
135 'default' => '',
136 'help' => 'help',
137 'required' => true,
138 ],
139 'name' => [
140 'name' => 'name',
141 'label' => __( 'Name', 'pods' ),
142 'type' => 'slug',
143 'default' => '',
144 'attributes' => [
145 'maxlength' => 50,
146 ],
147 'help' => 'help',
148 'required' => true,
149 ],
150 'description' => [
151 'name' => 'description',
152 'label' => __( 'Description', 'pods' ),
153 'type' => 'text',
154 'default' => '',
155 'help' => 'help',
156 ],
157 'type' => [
158 'name' => 'type',
159 'label' => __( 'Field Type', 'pods' ),
160 'type' => 'pick',
161 'default' => 'text',
162 'required' => true,
163 'data' => [],
164 'pick_format_single' => 'dropdown',
165 'dependency' => true,
166 'help' => 'help',
167 ],
168 'pick_object' => [
169 'name' => 'pick_object',
170 'label' => __( 'Related Type', 'pods' ),
171 'type' => 'pick',
172 'default' => 'custom-simple',
173 'required' => true,
174 'data' => [],
175 'pick_format_single' => 'dropdown',
176 'pick_show_select_text' => 0,
177 'dependency' => true,
178 'depends-on' => [
179 'type' => 'pick',
180 ],
181 'help' => 'help',
182 ],
183 'pick_custom' => [
184 'name' => 'pick_custom',
185 'label' => __( 'Custom Defined Options', 'pods' ),
186 'type' => 'paragraph',
187 'default' => '',
188 'required' => true,
189 'depends-on' => [
190 'type' => 'pick',
191 'pick_object' => 'custom-simple',
192 ],
193 'help' => __( 'One option per line, use <em>value|Label</em> for separate values and labels', 'pods' ),
194 ],
195 'pick_table' => [
196 'name' => 'pick_table',
197 'label' => __( 'Related Table', 'pods' ),
198 'type' => 'pick',
199 'default' => '',
200 'data' => [],
201 'pick_format_single' => 'dropdown',
202 'pick_show_select_text' => 0,
203 'depends-on' => [
204 'type' => 'pick',
205 'pick_object' => 'table',
206 ],
207 'help' => 'help',
208 ],
209 'sister_id' => [
210 'name' => 'sister_id',
211 'label' => __( 'Bi-directional Field', 'pods' ),
212 'type' => 'pick',
213 'default' => '',
214 'data' => [],
215 'pick_format_single' => 'dropdown',
216 'depends-on' => [
217 'type' => 'pick',
218 'pick_object' => PodsForm::field_method( 'pick', 'bidirectional_objects' ),
219 ],
220 'help' => __( 'Bi-directional fields will update their related field for any item you select. This feature is only available for two relationships between two Pods.<br /><br />For example, when you update a Parent pod item to relate to a Child item, when you go to edit that Child item you will see the Parent pod item selected.', 'pods' ),
221 ],
222 'required' => [
223 'name' => 'required',
224 'label' => __( 'Required', 'pods' ),
225 'type' => 'boolean',
226 'default' => 0,
227 'boolean_yes_label' => '',
228 'excludes-on' => [
229 'type' => $layout_non_input_field_types,
230 ],
231 'help' => __( 'This will require a non-empty value to be entered.', 'pods' ),
232 ],
233 'required_help_boolean' => [
234 'name' => 'required_help_boolean',
235 'label' => '',
236 'type' => 'html',
237 'default' => 0,
238 'html_content' => '<p><em>' . esc_html__( 'Please note: When Yes/No fields are required, the field must be set to Yes (checked) to be able to submit the form.', 'pods' ) . '</em></p>',
239 'dependency' => true,
240 'depends-on' => [
241 'required' => true,
242 'type' => 'boolean',
243 ],
244 ],
245 ];
246
247
248 // Only non table-based Pods can have repeatable fields.
249 if ( $pod->is_table_based() ) {
250 $options['repeatable'] = [
251 'repeatable_message' => [
252 'name' => 'repeatable_message',
253 'label' => '',
254 'type' => 'html',
255 'html_content' => '<div class="notice"><p>' . esc_html__( 'Repeatable fields are currently not available for Pods that use table-based storage.', 'pods' ) . '</p></div>',
256 ],
257 ];
258 } else {
259 $options['repeatable'] = [
260 'repeatable' => [
261 'name' => 'repeatable',
262 'label' => __( 'Repeatable', 'pods' ),
263 'default' => 0,
264 'type' => 'boolean',
265 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add / Remove / Reorder additional values.', 'pods' ),
266 'boolean_yes_label' => __( 'Allow multiple values', 'pods' ),
267 'dependency' => true,
268 'depends-on' => [
269 'type' => $repeatable_field_types,
270 ],
271 ],
272 'repeatable_add_new_label' => [
273 'name' => 'repeatable_add_new_label',
274 'label' => __( 'Repeatable - Add New Label', 'pods' ),
275 'placeholder' => __( 'Add New', 'pods' ),
276 'default' => '',
277 'type' => 'text',
278 'depends-on' => [
279 'type' => $repeatable_field_types,
280 'repeatable' => true,
281 ],
282 ],
283 'repeatable_format' => [
284 'label' => __( 'Repeatable - Display Format', 'pods' ),
285 'help' => __( 'Used as format for front-end display', 'pods' ),
286 'depends-on' => [
287 'type' => $serial_repeatable_field_types,
288 'repeatable' => true,
289 ],
290 'default' => 'default',
291 'required' => true,
292 'type' => 'pick',
293 'data' => [
294 'default' => __( 'Item 1, Item 2, and Item 3', 'pods' ),
295 'non_serial' => __( 'Item 1, Item 2 and Item 3', 'pods' ),
296 'br' => __( 'Line breaks', 'pods' ),
297 'ul' => __( 'Unordered list', 'pods' ),
298 'ol' => __( 'Ordered list', 'pods' ),
299 'custom' => __( 'Custom separator (without "and")', 'pods' ),
300 ],
301 'pick_format_single' => 'dropdown',
302 'pick_show_select_text' => 0,
303 'dependency' => true,
304 ],
305 'repeatable_format_separator' => [
306 'label' => __( 'Repeatable - Display Format Separator', 'pods' ),
307 'help' => __( 'Used as separator for front-end display. Be sure to include exactly the spaces that you need since the separator is used literally between values. For example, you would use ", " to have values like "One, Two, Three". You would also use " | " to have values like "One | Two | Three".', 'pods' ),
308 'description' => __( 'This option will default to ", "', 'pods' ),
309 'depends-on' => [
310 'type' => $serial_repeatable_field_types,
311 'repeatable' => true,
312 'repeatable_format' => 'custom',
313 ],
314 'placeholder' => '',
315 'type' => 'text',
316 ],
317 ];
318 }
319
320 $options['advanced'] = [
321 'visual' => [
322 'name' => 'visual',
323 'label' => __( 'Visual', 'pods' ),
324 'type' => 'heading',
325 ],
326 'class' => [
327 'name' => 'class',
328 'label' => __( 'Additional CSS Classes', 'pods' ),
329 'help' => __( 'You can provide additional CSS classes separated by spaces to be output for the field markup.', 'pods' ),
330 'type' => 'text',
331 'default' => '',
332 ],
333 'values' => [
334 'name' => 'values',
335 'label' => __( 'Values', 'pods' ),
336 'type' => 'heading',
337 'excludes-on' => [
338 'type' => $layout_non_input_field_types,
339 ],
340 ],
341 'default_value' => [
342 'name' => 'default_value',
343 'label' => __( 'Default Value', 'pods' ),
344 'help' => __( 'This is the default value used when the Add New form is used. For multiple-value fields, you can separate multiple default values with commas.', 'pods' ),
345 'description' => __( 'This value is only used on Add New forms', 'pods' ),
346 'type' => 'text',
347 'default' => '',
348 'text_max_length' => - 1,
349 'excludes-on' => [
350 'type' => $layout_non_input_field_types,
351 ],
352 ],
353 'default_value_parameter' => [
354 'name' => 'default_value_parameter',
355 'label' => __( 'Set Default Value via Parameter', 'pods' ),
356 'help' => __( 'You can automatically populate the value of this field from the URL parameter "your_field" such as ?your_field=1234', 'pods' ),
357 'type' => 'text',
358 'default' => '',
359 'excludes-on' => [
360 'type' => $layout_non_input_field_types,
361 ],
362 ],
363 'default_evaluate_tags' => [
364 'name' => 'default_evaluate_tags',
365 'label' => __( 'Evaluate tags in default values', 'pods' ),
366 'help' => __( 'Whether to evaluate tags like {@user.ID} in your default value. This does NOT evaluate tags passed dynamically via Parameter.', 'pods' ),
367 'type' => 'boolean',
368 'default' => false,
369 'boolean_yes_label' => __( 'Evaluate tags like {@user.ID} in the default value', 'pods' ),
370 'excludes-on' => [
371 'type' => $layout_non_input_field_types,
372 ],
373 ],
374 'default_empty_fields' => [
375 'name' => 'default_empty_fields',
376 'label' => __( 'Default Empty Fields in Forms', 'pods' ),
377 'help' => __( 'On forms where the field value is empty you can enable Default Empty Fields to override the value with your chosen default value.', 'pods' ),
378 'type' => 'boolean',
379 'default' => false,
380 'boolean_yes_label' => __( 'Use the default value when this field is empty', 'pods' ),
381 'excludes-on' => [
382 'type' => $layout_non_input_field_types,
383 ],
384 ],
385 'visibility' => [
386 'name' => 'visibility',
387 'label' => __( 'Visibility', 'pods' ),
388 'type' => 'heading',
389 ],
390 'restrict_access' => [
391 'type' => 'boolean_group',
392 'name' => 'restrict_access',
393 'label' => __( 'Restrict Access', 'pods' ),
394 'boolean_group' => [
395 'logged_in_only' => [
396 'name' => 'logged_in_only',
397 'label' => __( 'Restrict access to Logged In Users', 'pods' ),
398 'default' => 0,
399 'type' => 'boolean',
400 'dependency' => true,
401 'help' => __( 'This field will only be able to be edited by logged in users. This is not required to be on for the other Restrict Access options to work.', 'pods' ),
402 ],
403 'admin_only' => [
404 'name' => 'admin_only',
405 'label' => __( 'Restrict access to Admins', 'pods' ),
406 'default' => 0,
407 'type' => 'boolean',
408 'dependency' => true,
409 'help' => __( 'This field will only be able to be edited by users with the ability to manage_options or delete_users, or super admins of a WordPress Multisite network', 'pods' ),
410 ],
411 'restrict_role' => [
412 'name' => 'restrict_role',
413 'label' => __( 'Restrict access by Role', 'pods' ),
414 'default' => 0,
415 'type' => 'boolean',
416 'dependency' => true,
417 ],
418 'restrict_capability' => [
419 'name' => 'restrict_capability',
420 'label' => __( 'Restrict access by Capability', 'pods' ),
421 'default' => 0,
422 'type' => 'boolean',
423 'dependency' => true,
424 ],
425 ],
426 ],
427 'roles_allowed' => [
428 'name' => 'roles_allowed',
429 'label' => __( 'Role(s) Allowed', 'pods' ),
430 'help' => __( 'If none are selected, this option will be ignored.', 'pods' ),
431 'type' => 'pick',
432 'pick_object' => 'role',
433 'pick_format_type' => 'multi',
434 'default' => 'administrator',
435 'depends-on' => [
436 'restrict_role' => true,
437 ],
438 ],
439 'capability_allowed' => [
440 'name' => 'capability_allowed',
441 'label' => __( 'Capability Allowed', 'pods' ),
442 'help' => __( 'Comma-separated list of capabilities, for example add_podname_item, please see the Roles and Capabilities component for the complete list and a way to add your own.', 'pods' ),
443 'type' => 'text',
444 'default' => '',
445 'depends-on' => [
446 'restrict_capability' => true,
447 ],
448 ],
449 'ui_access' => [
450 'type' => 'boolean_group',
451 'name' => 'ui_access',
452 'label' => __( 'UI Access', 'pods' ),
453 'boolean_group' => [
454 'hidden' => [
455 'name' => 'hidden',
456 'label' => __( 'Hide field in forms', 'pods' ),
457 'default' => 0,
458 'type' => 'boolean',
459 'help' => __( 'This option is overridden by access restrictions. If the user does not have access to edit this field, it will be hidden. If no access restrictions are set, this field will always be hidden.', 'pods' ),
460 ],
461 'read_only' => [
462 'name' => 'read_only',
463 'label' => __( 'Make field "Read Only" in forms always', 'pods' ),
464 'default' => 0,
465 'type' => 'boolean',
466 'help' => __( 'This option is NOT overridden by access restrictions. The field will always show as "Read Only". This does not prevent the field from being changed manually through HTML DOM manipulation, this just shows the field as a read-only text field that cannot be normally changed without developer intervention.', 'pods' ),
467 'depends-on' => [
468 'type' => [
469 'boolean',
470 'color',
471 'currency',
472 'date',
473 'datetime',
474 'email',
475 'number',
476 'paragraph',
477 'password',
478 'phone',
479 'slug',
480 'text',
481 'time',
482 'website',
483 ],
484 ],
485 'dependency' => true,
486 ],
487 'read_only_restricted' => [
488 'name' => 'read_only_restricted',
489 'label' => __( 'Make field "Read Only" in forms only when restricted', 'pods' ),
490 'default' => 0,
491 'type' => 'boolean',
492 'help' => __( 'Normally restricted fields are not shown when restricted but this option will cause the field to show as "Read Only" in those cases. This can be used without making the whole field "Read Only" so that people with access can continue editing the value.', 'pods' ),
493 'depends-on-any' => [
494 'logged_in_only' => true,
495 'admin_only' => true,
496 'restrict_role' => true,
497 'restrict_capability' => true,
498 ],
499 'depends-on' => [
500 'read_only' => false,
501 ],
502 ],
503 ],
504 ],
505 ];
506
507 if ( 'post_type' === $pod->get_type() && 'meta' === $pod->get_storage() ) {
508 $options['advanced']['other_options'] = [
509 'name' => 'other_options',
510 'label' => __( 'Other Options', 'pods' ),
511 'type' => 'heading',
512 'depends-on' => [
513 'type' => PodsForm::revisionable_field_types(),
514 ],
515 ];
516
517 $options['advanced']['revisions_revision_field'] = [
518 'name' => 'revisions_revision_field',
519 'label' => __( 'Track field value changes in revisions', 'pods' ),
520 'help' => __( 'Revisions allow comparing and restoring previous saved changes. This setting requires revisions to be enabled on the pod. Revisions for meta as of WordPress 6.5 does not have additional UI to show the custom field value differences in the Revisions UI but upon restoring a revision those covered meta field values will be restored too while leaving non-covered meta field values in place.', 'pods' ),
521 'type' => 'boolean',
522 'default' => false,
523 'boolean_yes_label' => __( 'Track field value changes for this field.', 'pods' ),
524 'depends-on' => [
525 'type' => PodsForm::revisionable_field_types(),
526 ],
527 ];
528 }
529
530 $options['conditional-logic'] = [
531 'enable_conditional_logic' => [
532 'name' => 'enable_conditional_logic',
533 'label' => __( 'Enable Conditional Logic', 'pods' ),
534 'help' => __( 'Conditional logic can automatically show or hide this field depending on the value of other fields.', 'pods' ),
535 'type' => 'boolean',
536 'default' => 0,
537 ],
538 'conditional_logic' => [
539 'name' => 'conditional_logic',
540 'label' => __( 'Conditions', 'pods' ),
541 'type' => 'conditional-logic',
542 'depends-on' => [
543 'enable_conditional_logic' => true,
544 ],
545 ],
546 'conditional_logic_save_value' => [
547 'name' => 'conditional_logic_save_value',
548 'label' => __( 'Save Value When Hidden', 'pods' ),
549 'help' => __( 'When enabled, the field value will be saved even when the field is hidden by conditional logic.', 'pods' ),
550 'type' => 'boolean',
551 'default' => 0,
552 'boolean_yes_label' => __( 'Preserve field value when conditionally hidden', 'pods' ),
553 'depends-on' => [
554 'enable_conditional_logic' => true,
555 ],
556 ],
557 'conditional_logic_help' => [
558 'name' => 'conditional_logic_help',
559 'label' => '',
560 'type' => 'html',
561 'html_content' => wpautop(
562 sprintf(
563 '
564 %1$s
565
566 <ul>
567 <li>%2$s</li>
568 <li>%3$s</li>
569 </ul>
570
571 <a href="https://docs.pods.io/fields/conditional-logic-for-fields/">%4$s &raquo;</a>
572 ',
573 __( 'Each field type has their own conditional options available to them.', 'pods' ),
574 __( 'For pattern matching on text-based fields: Use Regular Expressions and do not use the wrapping character "/" like "/[a-z]/", you will need to use "[a-z]"', 'pods' ),
575 __( 'For relationships: Use the ID for any relationship object or the text value for any custom defined / simple relationship', 'pods' ),
576 __( 'Learn more about conditional logic for fields', 'pods' )
577 )
578 ),
579 'depends-on' => [
580 'enable_conditional_logic' => true,
581 ],
582 ],
583 ];
584
585 $pick_tables = pods_transient_get( 'pods_tables' );
586
587 if ( empty( $pick_tables ) ) {
588 $pick_tables = [
589 '' => __( '-- Select Table --', 'pods' ),
590 ];
591
592 global $wpdb;
593
594 $tables = $wpdb->get_results( 'SHOW TABLES', ARRAY_N );
595
596 if ( ! empty( $tables ) ) {
597 foreach ( $tables as $table ) {
598 $pick_tables[ $table[0] ] = $table[0];
599 }
600 }
601
602 pods_transient_set( 'pods_tables', $pick_tables, WEEK_IN_SECONDS );
603 }
604
605 $field_settings = [
606 'field_types_select' => [],
607 'pick_object' => PodsForm::field_method( 'pick', 'related_objects', true ),
608 'pick_table' => $pick_tables,
609 'sister_id' => [
610 '' => __( 'No Related Fields Found', 'pods' ),
611 ],
612 ];
613
614 $pod_name = $pod['name'];
615 $pod_type = $pod['type'];
616
617 foreach ( $field_types as $type => $field_type_data ) {
618 /**
619 * @var $field_type PodsField
620 */
621 $field_type_object = PodsForm::field_loader( $type, $field_type_data['file'] );
622
623 $field_type_vars = get_class_vars( get_class( $field_type_object ) );
624
625 if ( ! isset( $field_type_vars['pod_types'] ) ) {
626 $field_type_vars['pod_types'] = true;
627 }
628
629 $options[ 'additional-field-' . $type ] = [];
630
631 // Only show supported field types
632 if ( true !== $field_type_vars['pod_types'] ) {
633 if ( empty( $field_type_vars['pod_types'] ) ) {
634 continue;
635 } elseif ( is_array( $field_type_vars['pod_types'] ) && ! in_array( $pod_type, $field_type_vars['pod_types'], true ) ) {
636 continue;
637 } elseif ( ! is_array( $field_type_vars['pod_types'] ) && $pod_type !== $field_type_vars['pod_types'] ) {
638 continue;
639 }
640 }
641
642 if ( ! empty( PodsForm::$field_group ) ) {
643 if ( ! isset( $field_settings['field_types_select'][ PodsForm::$field_group ] ) ) {
644 $field_settings['field_types_select'][ PodsForm::$field_group ] = [];
645 }
646
647 $field_settings['field_types_select'][ PodsForm::$field_group ][ $type ] = $field_type_data['label'];
648 } else {
649 if ( ! isset( $field_settings['field_types_select'][ __( 'Other', 'pods' ) ] ) ) {
650 $field_settings['field_types_select'][ __( 'Other', 'pods' ) ] = [];
651 }
652
653 $field_settings['field_types_select'][ __( 'Other', 'pods' ) ][ $type ] = $field_type_data['label'];
654 }
655
656 $type_options = PodsForm::ui_options( $type );
657
658 $dev_mode = pods_developer();
659
660 if ( ! $dev_mode ) {
661 foreach ( $type_options as $type_option => $option_data ) {
662 if ( ! empty( $option_data['developer_mode'] ) ) {
663 unset( $type_options[ $type_option ] );
664 }
665 }
666 }
667
668 /**
669 * Modify Additional Field Options tab for a specific field type.
670 *
671 * @since 2.7.0
672 *
673 * @param array $type_options Additional field type options.
674 * @param string $type Field type.
675 * @param array $options Tabs, indexed by label.
676 * @param null|\Pods\Whatsit\Pod $pod Pods object for the Pod this UI is for.
677 */
678 $type_options = apply_filters( "pods_admin_setup_edit_{$type}_additional_field_options", $type_options, $type, $options, $pod );
679
680 /**
681 * Modify Additional Field Options tab.
682 *
683 * @since 2.7.0
684 *
685 * @param array $type_options Additional field type options.
686 * @param string $type Field type.
687 * @param array $options Tabs, indexed by label.
688 * @param null|\Pods\Whatsit\Pod $pod Pods object for the Pod this UI is for.
689 */
690 $type_options = apply_filters( 'pods_admin_setup_edit_additional_field_options', $type_options, $type, $options, $pod );
691
692 $options[ 'additional-field-' . $type ] = $type_options;
693 }//end foreach
694
695 /**
696 * Allow filtering the field settings by pod name.
697 *
698 * @param array $field_settings List of field settings to use.
699 * @param null|\Pods\Whatsit\Pod $pod Pods object for the Pod this UI is for.
700 * @param array $tabs List of registered tabs
701 */
702 $field_settings = apply_filters( "pods_field_settings_{$pod_name}", $field_settings, $pod, $tabs );
703
704 /**
705 * Allow filtering the field settings by pod name.
706 *
707 * @param array $field_settings List of field settings to use.
708 * @param null|\Pods\Whatsit\Pod $pod Pods object for the Pod this UI is for.
709 * @param array $tabs List of registered tabs
710 */
711 $field_settings = apply_filters( 'pods_field_settings', $field_settings, $pod, $tabs );
712
713 $options['basic']['type']['data'] = $field_settings['field_types_select'];
714 $options['basic']['pick_object']['data'] = $field_settings['pick_object'];
715 $options['basic']['pick_table']['data'] = $field_settings['pick_table'];
716
717 // @todo Look into supporting these in the future.
718 /*
719 'search' => [
720 'label' => __( 'Include in searches', 'pods' ),
721 'default' => 1,
722 'type' => 'boolean',
723 ],
724 'regex_validation' => [
725 'label' => __( 'RegEx Validation', 'pods' ),
726 'type' => 'text',
727 'default' => '',
728 ],
729 'message_regex' => [
730 'label' => __( 'Message if field does not pass RegEx', 'pods' ),
731 'type' => 'text',
732 'default' => '',
733 ],
734 'message_required' => [
735 'label' => __( 'Message if field is blank', 'pods' ),
736 'type' => 'text',
737 'default' => '',
738 'depends-on' => [ 'required' => true ],
739 ],
740 'message_unique' => [
741 'label' => __( 'Message if field is not unique', 'pods' ),
742 'type' => 'text',
743 'default' => '',
744 'depends-on' => [ 'unique' => true ],
745 ],
746 */
747
748 if ( 'table' === $pod['storage'] || 'pod' === $pod['type'] ) {
749 unset( $options['basic']['repeatable'] );
750
751 $options['basic']['unique'] = [
752 'name' => 'unique',
753 'label' => __( 'Unique', 'pods' ),
754 'type' => 'boolean',
755 'default' => 0,
756 'boolean_yes_label' => '',
757 'help' => __( 'This will require that the field value entered is unique and has not been saved before.', 'pods' ),
758 'excludes-on' => [
759 'type' => $tableless_field_types,
760 ],
761 ];
762 }
763
764 // Only include kitchen sink if dev mode on and not running Codecept tests.
765 if ( pods_developer() && ! function_exists( 'codecept_debug' ) ) {
766 $options['kitchen-sink'] = json_decode( file_get_contents( PODS_DIR . 'tests/codeception/_data/kitchen-sink-config.json' ), true );
767 }
768
769 $pod_type = $pod['type'];
770 $pod_name = $pod['name'];
771
772 /**
773 * Add admin fields to the Pod Fields editor for a specific Pod.
774 *
775 * @since 2.8.0
776 *
777 * @param array $options The Options fields.
778 * @param \Pods\Whatsit\Pod $pod Current Pods object.
779 * @param array $tabs List of registered tabs.
780 */
781 $options = apply_filters( "pods_admin_setup_edit_field_options_{$pod_type}_{$pod_name}", $options, $pod, $tabs );
782
783 /**
784 * Add admin fields to the Pod Fields editor for any Pod of a specific content type.
785 *
786 * @since 2.8.0
787 *
788 * @param array $options The Options fields.
789 * @param \Pods\Whatsit\Pod $pod Current Pods object.
790 * @param array $tabs List of registered tabs.
791 */
792 $options = apply_filters( "pods_admin_setup_edit_field_options_{$pod_type}", $options, $pod, $tabs );
793
794 /**
795 * Add admin fields to the Pod Fields editor for all Pods.
796 *
797 * @since 2.8.0
798 *
799 * @param array $options The Options fields.
800 * @param \Pods\Whatsit\Pod $pod Current Pods object.
801 * @param array $tabs List of registered tabs.
802 */
803 $options = apply_filters( 'pods_admin_setup_edit_field_options', $options, $pod, $tabs );
804
805 return $options;
806 }
807 }
808