class-gf-field-list.php
22.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
<?php
// If Gravity Forms isn't loaded, bail.
if ( ! class_exists( 'GFForms' ) ) {
die();
}
/**
* Class GF_Field_List
*
* Handles the behavior of List fields.
*
* @since Unknown
*/
class GF_Field_List extends GF_Field {
/**
* Sets the field type for the List field.
*
* @since Unknown
* @access public
*
* @var string The field type.
*/
public $type = 'list';
/**
* Sets the field title to be displayed in the form editor.
*
* @since Unknown
* @access public
*
* @used-by GFCommon::get_field_type_title()
* @used-by GFAddOn::get_field_map_choices()
* @used-by GF_Field::get_form_editor_button()
*
* @return string The field title. Escaped and translatable.
*/
public function get_form_editor_field_title() {
return esc_attr__( 'List', 'gravityforms' );
}
/**
* Defines the field settings available in the form editor.
*
* @since Unknown
* @access public
*
* @used-by GFFormDetail::inline_scripts()
*
* @return array The settings available.
*/
function get_form_editor_field_settings() {
return array(
'columns_setting',
'maxrows_setting',
'add_icon_url_setting',
'delete_icon_url_setting',
'conditional_logic_field_setting',
'prepopulate_field_setting',
'error_message_setting',
'label_setting',
'label_placement_setting',
'admin_label_setting',
'rules_setting',
'visibility_setting',
'description_setting',
'css_class_setting',
);
}
/**
* Gets the ID of the first input.
*
* @since Unknown
* @access public
*
* @uses GF_Field::is_form_editor()
* @uses GF_Field_List::$id
*
* @param array $form The Form Object.
*
* @return string The ID of the first input. Empty string if not found.
*/
public function get_first_input_id( $form ) {
return ! $this->is_form_editor() ? sprintf( 'input_%s_%s_shim', $form['id'], $this->id ) : '';
}
/**
* Defines if the inline style block has been printed.
*
* @since Unknown
* @access private
*
* @used-by GF_Field_List::get_field_input()
*
* @var bool false
*/
private static $_style_block_printed = false;
/**
* Builds the field input HTML markup.
*
* @since Unknown
* @access public
*
* @used-by GFCommon::get_field_input()
* @uses GF_Field::is_entry_detail()
* @uses GF_Field::is_form_editor()
* @uses GF_Field_List::$_style_block_printed
* @uses GF_Field_List::$maxRow
* @uses GF_Field_List::$addIconUrl
* @uses GF_Field_List::$deleteIconUrl
* @uses GFCommon::get_base_url()
*
* @param array $form The Form Object.
* @param string $value The field value. Defaults to empty string.
* @param null|array $entry The Entry Object. Defaults to null.
*
* @return string The List field HTML markup.
*/
public function get_field_input( $form, $value = '', $entry = null ) {
$form_id = $form['id'];
$is_entry_detail = $this->is_entry_detail();
$is_form_editor = $this->is_form_editor();
$disabled_text = $is_form_editor ? 'disabled="disabled"' : '';
if ( ! empty( $value ) ) {
$value = maybe_unserialize( $value );
}
if ( ! is_array( $value ) ) {
$value = array( array() );
}
$has_columns = is_array( $this->choices );
$columns = $has_columns ? $this->choices : array( array() );
$shim_style = is_rtl() ? 'position:absolute;left:999em;' : 'position:absolute;left:-999em;';
$label_target_shim = sprintf( '<input type=\'text\' id=\'input_%1$s_%2$s_shim\' style=\'%3$s\' onfocus=\'jQuery( "#field_%1$s_%2$s table tr td:first-child input" ).focus();\' />', $form_id, $this->id, $shim_style );
$list = '';
if ( ! self::$_style_block_printed ){
// This style block needs to be inline so that the list field continues to work even if the option to turn off CSS output is activated.
$list .= '<style type="text/css">
body .ginput_container_list table.gfield_list tbody tr td.gfield_list_icons {
vertical-align: middle !important;
}
body .ginput_container_list table.gfield_list tbody tr td.gfield_list_icons img.add_list_item,
body .ginput_container_list table.gfield_list tbody tr td.gfield_list_icons img.delete_list_item {
background-color: transparent !important;
background-position: 0 0;
background-size: 16px 16px !important;
background-repeat: no-repeat;
border: none !important;
width: 16px !important;
height: 16px !important;
opacity: 0.5;
transition: opacity .5s ease-out;
-moz-transition: opacity .5s ease-out;
-webkit-transition: opacity .5s ease-out;
-o-transition: opacity .5s ease-out;
}
body .ginput_container_list table.gfield_list tbody tr td.gfield_list_icons img.add_list_item:hover,
body .ginput_container_list table.gfield_list tbody tr td.gfield_list_icons img.delete_list_item:hover {
opacity: 1.0;
}
</style>';
self::$_style_block_printed = true;
}
$list .= "<div class='ginput_container ginput_container_list ginput_list'>" .
$label_target_shim .
"<table class='gfield_list gfield_list_container'>";
$class_attr = '';
if ( $has_columns ) {
$list .= '<colgroup>';
for ( $colnum = 1; $colnum <= count( $columns ) + 1; $colnum++ ) {
$odd_even = ( $colnum % 2 ) == 0 ? 'even' : 'odd';
$list .= sprintf( "<col id='gfield_list_%d_col_%d' class='gfield_list_col_%s' />", $this->id, $colnum, $odd_even );
}
$list .= '</colgroup>';
$list .= '<thead><tr>';
foreach ( $columns as $column ) {
$list .= '<th>' . esc_html( $column['text'] ) . '</th>';
}
$list .= '<th> </th></tr></thead>';
} else {
$list .=
'<colgroup>' .
"<col id='gfield_list_{$this->id}_col1' class='gfield_list_col_odd' />" .
"<col id='gfield_list_{$this->id}_col2' class='gfield_list_col_even' />" .
'</colgroup>';
}
$delete_display = count( $value ) == 1 ? 'visibility:hidden;' : '';
$maxRow = intval( $this->maxRows );
$disabled_icon_class = ! empty( $maxRow ) && count( $value ) >= $maxRow ? 'gfield_icon_disabled' : '';
$add_icon = ! empty( $this->addIconUrl ) ? $this->addIconUrl : GFCommon::get_base_url() . '/images/list-add.svg';
$delete_icon = ! empty( $this->deleteIconUrl ) ? $this->deleteIconUrl : GFCommon::get_base_url() . '/images/list-remove.svg';
$add_events = $is_form_editor ? '' : "onclick='gformAddListItem(this, {$maxRow})' onkeypress='gformAddListItem(this, {$maxRow})'";
$delete_events = $is_form_editor ? '' : "onclick='gformDeleteListItem(this, {$maxRow})' onkeypress='gformDeleteListItem(this, {$maxRow})'";
$list .= '<tbody>';
$rownum = 1;
foreach ( $value as $item ) {
$odd_even = ( $rownum % 2 ) == 0 ? 'even' : 'odd';
$list .= "<tr class='gfield_list_row_{$odd_even} gfield_list_group'>";
$colnum = 1;
foreach ( $columns as $column ) {
$data_label = '';
// Getting value. Taking into account columns being added/removed from form meta.
if ( is_array( $item ) ) {
if ( $has_columns ) {
$val = rgar( $item, $column['text'] );
$data_label = "data-label='" . esc_attr( $column['text'] ) . "'";
} else {
$vals = array_values( $item );
$val = rgar( $vals, 0 );
}
} else {
$val = $colnum == 1 ? $item : '';
}
$list .= "<td class='gfield_list_cell gfield_list_{$this->id}_cell{$colnum}' {$data_label}>" . $this->get_list_input( $has_columns, $column, $val, $form_id ) . '</td>';
$colnum ++;
}
if ( $this->maxRows != 1 ) {
// Can't replace these icons with the webfont versions since they appear on the front end.
$list .= "<td class='gfield_list_icons'>";
$list .= " <img src='{$add_icon}' class='add_list_item {$disabled_icon_class}' {$disabled_text} title='" . esc_attr__( 'Add another row', 'gravityforms' ) . "' alt='" . esc_attr__( 'Add a new row', 'gravityforms' ) . "' {$add_events} style='cursor:pointer;' " . $this->get_tabindex() . "/>" .
" <img src='{$delete_icon}' class='delete_list_item' {$disabled_text} title='" . esc_attr__( 'Remove this row', 'gravityforms' ) . "' alt='" . esc_attr__( 'Remove this row', 'gravityforms' ) . "' {$delete_events} style='cursor:pointer; {$delete_display}' " . $this->get_tabindex() . "/>";
$list .= '</td>';
}
$list .= '</tr>';
if ( ! empty( $maxRow ) && $rownum >= $maxRow ) {
break;
}
$rownum ++;
}
$list .= '</tbody>';
$list .= '</table></div>';
return $list;
}
/**
* Builds the input that will be inside the List field.
*
* @since Unknown
* @access public
*
* @uses GF_Field::get_tabindex()
* @uses GF_Field::is_form_editor()
* @uses GF_Field_List::$choices
*
* @param bool $has_columns If the input has columns.
* @param array $column The column details.
* @param string $value The existing value of the input.
* @param int $form_id The form ID.
*
* @return string The input HTML markup.
*/
public function get_list_input( $has_columns, $column, $value, $form_id ) {
$tabindex = $this->get_tabindex();
$disabled = $this->is_form_editor() ? 'disabled' : '';
$column_index = 1;
if ( $has_columns && is_array( $this->choices ) ) {
foreach ( $this->choices as $choice ) {
if ( $choice['text'] == $column['text'] ) {
break;
}
$column_index ++;
}
}
$input_info = array( 'type' => 'text' );
/**
* Filters the column input.
*
* @since Unknown
*
* @param array $input_info Information about the input. Contains the input type.
* @param object GF_Field_List Field object for this field type.
* @param string $column['text'] The column text value.
* @param int $form_id The form ID.
*/
$input_info = gf_apply_filters( array(
'gform_column_input',
$form_id,
$this->id,
$column_index
), $input_info, $this, rgar( $column, 'text' ), $value, $form_id );
switch ( $input_info['type'] ) {
case 'select' :
$input = "<select name='input_{$this->id}[]' {$tabindex} {$disabled} >";
if ( ! is_array( $input_info['choices'] ) ) {
$input_info['choices'] = array_map( 'trim', explode( ',', $input_info['choices'] ) );
}
foreach ( $input_info['choices'] as $choice ) {
if ( is_array( $choice ) ) {
$choice_value = $choice['value'];
$choice_text = $choice['text'];
$choice_selected = array_key_exists( 'isSelected', $choice ) ? $choice['isSelected'] : false;
} else {
$choice_value = $choice;
$choice_text = $choice;
$choice_selected = false;
}
$is_selected = empty( $value ) ? $choice_selected : $choice_value == $value;
$selected = $is_selected ? "selected='selected'" : '';
$input .= "<option value='" . esc_attr( $choice_value ) . "' {$selected}>" . esc_html( $choice_text ) . '</option>';
}
$input .= '</select>';
break;
default :
$input = "<input type='text' name='input_{$this->id}[]' value='" . esc_attr( $value ) . "' {$tabindex} {$disabled}/>";
break;
}
/**
* Filters the column input HTML markup.
*
* @since Unknown
*
* @param string $input The input markup.
* @param array $input_info The information that was used to build the input.
* @param object GF_Field_List An instance of the List field object.
* @param string $column['text'] The column text value.
* @param int $form_id The form ID.
*/
return gf_apply_filters( array(
'gform_column_input_content',
$form_id,
$this->id,
$column_index
), $input, $input_info, $this, rgar( $column, 'text' ), $value, $form_id );
}
/**
* Gets the CSS class to be used in the field label.
*
* @since Unknown
* @access public
*
* @used-by GF_Field::get_field_content()
*
* @return string String containing the CSS class names.
*/
public function get_field_label_class(){
$has_columns = is_array( $this->choices );
return $has_columns ? 'gfield_label gfield_label_before_complex' : 'gfield_label';
}
/**
* Gets the value of te field from the form submission.
*
* @since Unknown
* @access public
*
* @used-by GFFormsModel::get_field_value()
* @uses GF_Field::get_input_value_submission()
* @uses GF_Field_List::create_list_array()
*
* @param array $field_values The properties to search for.
* @param bool $get_from_post_global_var If the global GET variable should be used to obtain the value. Defaults to true.
*
* @return array The submission value.
*/
public function get_value_submission( $field_values, $get_from_post_global_var = true ) {
$value = $this->get_input_value_submission( 'input_' . $this->id, $this->inputName, $field_values, $get_from_post_global_var );
// Allow the value to be an array of row arrays in addition to the array of rows.
if ( is_array( rgar( $value, 0 ) ) ){
// Already in correct format, return value unchanged.
return $value;
}
// Not already in the correct format.
$value = $this->create_list_array( $value );
return $value;
}
/**
* Check if the submission value is empty.
*
* @since Unknown
* @access public
*
* @used-by GFFormDisplay::is_empty()
* @uses GF_Field_List::$id
*
* @param int $form_id The form ID to check.
*
* @return bool True if empty. False otherwise.
*/
public function is_value_submission_empty( $form_id ) {
$value = rgpost( 'input_' . $this->id );
if ( is_array( $value ) ) {
// Empty if all inputs are empty (for inputs with the same name).
foreach ( $value as $input ) {
if ( strlen( trim( $input ) ) > 0 ) {
return false;
}
}
}
return true;
}
/**
* Gets the field value HTML markup to be used on the entry detail page.
*
* @since Unknown
* @access public
*
* @used-by GFCommon::get_lead_field_display()
*
* @param array $value The submitted entry value.
* @param string $currency Not used.
* @param bool $use_text Not used.
* @param string $format The format to be used when building the items.
* Accepted values are text, url, or html. Defaults to html.
* @param string $media Defines how the content will be output.
* Accepted values are screen or email. Defaults to screen.
*
* @return string The HTML markup to be displayed.
*/
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
if ( empty( $value ) ) {
return '';
}
$value = maybe_unserialize( $value );
if( ! is_array( $value ) ) {
return '';
}
$has_columns = is_array( $value[0] );
if ( ! $has_columns ) {
$items = '';
foreach ( $value as $key => $item ) {
if ( ! empty( $item ) ) {
$item = wp_kses_post( $item );
switch ( $format ) {
case 'text' :
$items .= $item . ', ';
break;
case 'url' :
$items .= $item . ',';
break;
default :
if ( $media == 'email' ) {
$items .= "<li>{$item}</li>";
} else {
$items .= "<li>{$item}</li>";
}
break;
}
}
}
if ( empty( $items ) ) {
return '';
} elseif ( $format == 'text' ) {
return substr( $items, 0, strlen( $items ) - 2 ); // Removing last comma.
} elseif ( $format == 'url' ) {
return substr( $items, 0, strlen( $items ) - 1 ); // Removing last comma.
} elseif ( $media == 'email' ) {
return "<ul class='bulleted'>{$items}</ul>";
} else {
return "<ul class='bulleted'>{$items}</ul>";
}
} elseif ( is_array( $value ) ) {
$columns = array_keys( $value[0] );
$list = '';
switch ( $format ) {
case 'text' :
$is_first_row = true;
foreach ( $value as $item ) {
if ( ! $is_first_row ) {
$list .= "\n\n" . $this->label . ': ';
}
$item = array_map( 'wp_kses_post', $item );
$list .= implode( ',', array_values( $item ) );
$is_first_row = false;
}
break;
case 'url' :
foreach ( $value as $item ) {
$item = array_map( 'wp_kses_post', $item );
$list .= implode( "|", array_values( $item ) ) . ',';
}
if ( ! empty( $list ) ) {
$list = substr( $list, 0, strlen( $list ) - 1 );
}
break;
default :
if ( $media == 'email' ) {
$list = "<table class='gfield_list' style='border-top: 1px solid #DFDFDF; border-left: 1px solid #DFDFDF; border-spacing: 0; padding: 0; margin: 2px 0 6px; width: 100%'><thead><tr>\n";
//reading columns from entry data
foreach ( $columns as $column ) {
$list .= "<th style='background-image: none; border-right: 1px solid #DFDFDF; border-bottom: 1px solid #DFDFDF; padding: 6px 10px; font-family: sans-serif; font-size: 12px; font-weight: bold; background-color: #F1F1F1; color:#333; text-align:left'>" . esc_html( $column ) . '</th>' . "\n";
}
$list .= '</tr></thead>' . "\n";
$list .= "<tbody style='background-color: #F9F9F9'>";
foreach ( $value as $item ) {
$list .= '<tr>';
foreach ( $columns as $column ) {
$val = rgar( $item, $column );
$val = wp_kses_post( $val );
$list .= "<td style='padding: 6px 10px; border-right: 1px solid #DFDFDF; border-bottom: 1px solid #DFDFDF; border-top: 1px solid #FFF; font-family: sans-serif; font-size:12px;'>{$val}</td>\n";
}
$list .= '</tr>' . "\n";
}
$list .= '<tbody></table>' . "\n";
} else {
$list = "<table class='gfield_list'><thead><tr>";
// Reading columns from entry data.
foreach ( $columns as $column ) {
$list .= '<th>' . esc_html( $column ) . '</th>' . "\n";
}
$list .= '</tr></thead>' . "\n";
$list .= '<tbody>';
foreach ( $value as $item ) {
$list .= '<tr>';
foreach ( $columns as $column ) {
$val = rgar( $item, $column );
$val = wp_kses_post( $val );
$list .= "<td>{$val}</td>\n";
}
$list .= '</tr>' . "\n";
}
$list .= '<tbody></table>' . "\n";
}
break;
}
return $list;
}
return '';
}
/**
* Gets the value of the field when the entry is saved.
*
* @since Unknown
* @access public
*
* @used-by GFFormsModel::prepare_value()
* @uses GF_Field_List::$adminOnly
* @uses GF_Field_List::$allowsPrepopulate
* @uses GF_Field_List::create_list_array()
* @uses GFCommon::is_empty_array()
* @uses GF_Field::sanitize_entry_value()
*
* @param string $value The value to use.
* @param array $form The form that the entry is associated with.
* @param string $input_name The name of the input containing the value.
* @param int $lead_id The entry ID.
* @param array $lead The Entry Object.
*
* @return string The entry value. Escaped.
*/
public function get_value_save_entry( $value, $form, $input_name, $lead_id, $lead ) {
if ( $this->is_administrative() && $this->allowsPrepopulate ) {
$value = json_decode( $value );
}
if ( GFCommon::is_empty_array( $value ) ) {
$value = '';
} else {
$value = $this->create_list_array( $value );
$value = serialize( $value );
}
$value_safe = $this->sanitize_entry_value( $value, $form['id'] );
return $value_safe;
}
/**
* Gets merge tag values.
*
* @since Unknown
* @access public
*
* @used-by
* @uses GFCommon::get_lead_field_display()
*
* @param array|string $value The value of the input.
* @param string $input_id The input ID to use.
* @param array $entry The Entry Object.
* @param array $form The Form Object
* @param string $modifier The modifier passed.
* @param array|string $raw_value The raw value of the input.
* @param bool $url_encode If the result should be URL encoded.
* @param bool $esc_html If the HTML should be escaped.
* @param string $format The format that the value should be.
* @param bool $nl2br If the nl2br function should be used.
*
* @return string The processed merge tag.
*/
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
$output_format = in_array( $modifier, array( 'text', 'html', 'url' ) ) ? $modifier : $format;
return GFCommon::get_lead_field_display( $this, $raw_value, $entry['currency'], true, $output_format );
}
/**
* Creates an array from the list items.
*
* @since Unknown
* @access public
*
* @used-by GF_Field_List::get_value_save_entry()
* @used-by GF_Field_List::get_value_submission()
*
* @param array $value The pre-formatted list.
*
* @return array The list rows.
*/
function create_list_array( $value ) {
if ( ! $this->enableColumns ) {
return $value;
} else {
$col_count = count( $this->choices );
$rows = array();
$row_count = count( $value ) / $col_count;
$col_index = 0;
for ( $i = 0; $i < $row_count; $i ++ ) {
$row = array();
foreach ( $this->choices as $column ) {
$row[ $column['text'] ] = rgar( $value, $col_index );
$col_index ++;
}
$rows[] = $row;
}
return $rows;
}
}
/**
* Sanitizes the field settings.
*
* @since Unknown
* @access public
*
* @used-by GFFormDetail::add_field()
* @used-by GFFormsModel::sanitize_settings()
* @uses GF_Field::sanitize_settings()
* @uses GF_Field_List::$maxRows
*
* @return void
*/
public function sanitize_settings() {
parent::sanitize_settings();
$this->maxRows = absint( $this->maxRows );
}
/**
* Gets the field value, formatted for exports.
*
* @since Unknown
* @access public
*
* @used-by GFExport::start_export()
* @used-by GFAddOn::get_field_value()
* @uses GF_Field_List::$id
* @uses GF_Field_List::$enableColumns
* @uses GF_Field_List::$choices
* @uses GFCommon::implode_non_blank()
*
* @param array $entry The Entry Object.
* @param string $input_id Input ID to export. If not defined, uses the current input ID. Defaults to empty string.
* @param bool $use_text Not used. Defaults to false.
* @param bool $is_csv If the export should be formatted as CSV. Defaults to false.
*
* @return string
*/
public function get_value_export( $entry, $input_id = '', $use_text = false, $is_csv = false ) {
if ( empty( $input_id ) ) {
$input_id = $this->id;
} elseif ( ! ctype_digit( $input_id ) ) {
$field_id_array = explode( '.', $input_id );
$input_id = rgar( $field_id_array, 0 );
$column_num = rgar( $field_id_array, 1 );
}
$value = rgar( $entry, $input_id );
if ( empty( $value ) || $is_csv ) {
return $value;
}
$list_values = $column_values = unserialize( $value );
if ( isset( $column_num ) && is_numeric( $column_num ) && $this->enableColumns ) {
$column = rgars( $this->choices, "{$column_num}/text" );
$column_values = array();
foreach ( $list_values as $value ) {
$column_values[] = rgar( $value, $column );
}
} elseif ( $this->enableColumns ) {
return json_encode( $list_values );
}
return GFCommon::implode_non_blank( ', ', $column_values );
}
}
// Register the list field.
GF_Fields::register( new GF_Field_List() );