1
|
|
|
<?php |
2
|
|
|
$attributes = array(); |
3
|
|
|
$attributes['tabindex'] = 2; |
4
|
|
|
|
5
|
|
|
$pick_limit = (int) pods_var( $form_field_type . '_limit', $options, 0 ); |
6
|
|
|
$multiple = false; |
7
|
|
|
|
8
|
|
|
if ( 'multi' == pods_var( $form_field_type . '_format_type', $options ) && 1 != $pick_limit ) { |
9
|
|
|
$name .= '[]'; |
10
|
|
|
$attributes['multiple'] = 'multiple'; |
11
|
|
|
$multiple = true; |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
if ( ! is_array( $options['data'] ) && false !== $options['data'] && 0 < strlen( $options['data'] ) ) { |
15
|
|
|
$options['data'] = implode( ',', $options['data'] ); |
16
|
|
|
} else { |
17
|
|
|
$options['data'] = (array) pods_var_raw( 'data', $options, array(), null, true ); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
$attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options ); |
21
|
|
|
|
22
|
|
|
if ( pods_var( 'readonly', $options, false ) ) { |
23
|
|
|
$attributes['readonly'] = 'READONLY'; |
24
|
|
|
|
25
|
|
|
$attributes['class'] .= ' pods-form-ui-read-only'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$selection_made = false; |
29
|
|
|
?> |
30
|
|
|
<select<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?>> |
31
|
|
|
<?php |
32
|
|
|
foreach ( $options['data'] as $option_value => $option_label ) { |
|
|
|
|
33
|
|
|
if ( is_array( $option_label ) && isset( $option_label['label'] ) ) { |
34
|
|
|
$option_label = $option_label['label']; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
if ( is_array( $option_label ) ) { |
38
|
|
|
?> |
39
|
|
|
<optgroup label="<?php echo esc_attr( $option_value ); ?>"> |
40
|
|
|
<?php |
41
|
|
|
foreach ( $option_label as $sub_option_value => $sub_option_label ) { |
42
|
|
|
if ( is_array( $sub_option_label ) ) { |
43
|
|
|
if ( isset( $sub_option_label['label'] ) ) { |
44
|
|
|
$sub_option_label = $sub_option_label['label']; |
45
|
|
|
} else { |
46
|
|
|
$sub_option_label = $sub_option_value; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$sub_option_label = (string) $sub_option_label; |
51
|
|
|
|
52
|
|
|
$selected = ''; |
53
|
|
|
$options['selected'] = ''; |
54
|
|
|
|
55
|
|
|
if ( ! $selection_made && ( ( ! is_array( $value ) && (string) $sub_option_value === (string) $value ) || ( is_array( $value ) && ( in_array( $sub_option_value, $value ) || in_array( (string) $sub_option_value, $value ) ) ) ) ) { |
56
|
|
|
$selected = ' SELECTED'; |
57
|
|
|
$options['selected'] = 'selected'; |
58
|
|
|
|
59
|
|
|
if ( ! $multiple ) { |
60
|
|
|
$selection_made = true; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if ( is_array( $sub_option_value ) ) { |
65
|
|
|
?> |
66
|
|
|
<option<?php PodsForm::attributes( $sub_option_value, $name, $form_field_type . '_option', $options ); ?>><?php echo esc_html( $sub_option_label ); ?></option> |
67
|
|
|
<?php |
68
|
|
|
} else { |
69
|
|
|
?> |
70
|
|
|
<option value="<?php echo esc_attr( $sub_option_value ); ?>"<?php echo $selected; ?>><?php echo esc_html( $sub_option_label ); ?></option> |
71
|
|
|
<?php |
72
|
|
|
} |
73
|
|
|
}//end foreach |
74
|
|
|
?> |
75
|
|
|
</optgroup> |
76
|
|
|
<?php |
77
|
|
|
} else { |
78
|
|
|
$option_label = (string) $option_label; |
79
|
|
|
|
80
|
|
|
$selected = ''; |
81
|
|
|
$options['selected'] = ''; |
82
|
|
|
|
83
|
|
|
if ( ! $selection_made && ( ( ! is_array( $value ) && (string) $option_value === (string) $value ) || ( is_array( $value ) && ( in_array( $option_value, $value ) || in_array( (string) $option_value, $value ) ) ) ) ) { |
84
|
|
|
$selected = ' SELECTED'; |
85
|
|
|
$options['selected'] = 'selected'; |
86
|
|
|
|
87
|
|
|
if ( ! $multiple ) { |
88
|
|
|
$selection_made = true; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if ( is_array( $option_value ) ) { |
93
|
|
|
?> |
94
|
|
|
<option<?php PodsForm::attributes( $option_value, $name, $form_field_type . '_option', $options ); ?>><?php echo esc_html( $option_label ); ?></option> |
95
|
|
|
<?php |
96
|
|
|
} else { |
97
|
|
|
?> |
98
|
|
|
<option value="<?php echo esc_attr( $option_value ); ?>"<?php echo $selected; ?>><?php echo esc_html( $option_label ); ?></option> |
99
|
|
|
<?php |
100
|
|
|
} |
101
|
|
|
}//end if |
102
|
|
|
}//end foreach |
103
|
|
|
?> |
104
|
|
|
</select> |
105
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.