Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 62 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
PFDropdownInput | |
0.00% |
0 / 62 |
|
0.00% |
0 / 7 |
600 | |
0.00% |
0 / 1 |
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultPropTypes | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getOtherPropTypesHandled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultCargoTypes | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getOtherCargoTypesHandled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHTML | |
0.00% |
0 / 46 |
|
0.00% |
0 / 1 |
342 | |||
getHtmlText | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * @file |
4 | * @ingroup PF |
5 | */ |
6 | |
7 | /** |
8 | * @ingroup PFFormInput |
9 | */ |
10 | class PFDropdownInput extends PFEnumInput { |
11 | |
12 | public static function getName(): string { |
13 | return 'dropdown'; |
14 | } |
15 | |
16 | public static function getDefaultPropTypes() { |
17 | return [ |
18 | 'enumeration' => [] |
19 | ]; |
20 | } |
21 | |
22 | public static function getOtherPropTypesHandled() { |
23 | return [ '_boo' ]; |
24 | } |
25 | |
26 | public static function getDefaultCargoTypes() { |
27 | return [ |
28 | 'Enumeration' => [] |
29 | ]; |
30 | } |
31 | |
32 | public static function getOtherCargoTypesHandled() { |
33 | return [ 'Boolean' ]; |
34 | } |
35 | |
36 | public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, array $other_args ) { |
37 | global $wgPageFormsTabIndex, $wgPageFormsFieldNum; |
38 | |
39 | // Standardize $cur_value |
40 | if ( $cur_value === null ) { |
41 | $cur_value = ''; |
42 | } |
43 | |
44 | $className = ( $is_mandatory ) ? 'mandatoryField' : 'createboxInput'; |
45 | if ( array_key_exists( 'class', $other_args ) ) { |
46 | $className .= ' ' . $other_args['class']; |
47 | } |
48 | $input_id = "input_$wgPageFormsFieldNum"; |
49 | if ( array_key_exists( 'show on select', $other_args ) ) { |
50 | $className .= ' pfShowIfSelected'; |
51 | PFFormUtils::setShowOnSelect( $other_args['show on select'], $input_id ); |
52 | } |
53 | $innerDropdown = ''; |
54 | // Add a blank value at the beginning, unless this is a |
55 | // mandatory field and there's a current value in place |
56 | // (either through a default value or because we're editing |
57 | // an existing page). |
58 | if ( !$is_mandatory || $cur_value === '' ) { |
59 | $innerDropdown .= " <option value=\"\"></option>\n"; |
60 | } |
61 | $possible_values = $other_args['possible_values']; |
62 | if ( $possible_values == null ) { |
63 | // If it's a Boolean property, display 'Yes' and 'No' |
64 | // as the values. |
65 | if ( array_key_exists( 'property_type', $other_args ) && $other_args['property_type'] == '_boo' ) { |
66 | $possible_values = [ |
67 | PFUtils::getWordForYesOrNo( true ), |
68 | PFUtils::getWordForYesOrNo( false ), |
69 | ]; |
70 | } else { |
71 | $possible_values = []; |
72 | } |
73 | } |
74 | foreach ( $possible_values as $possible_value ) { |
75 | $optionAttrs = [ 'value' => $possible_value ]; |
76 | if ( $possible_value == $cur_value ) { |
77 | $optionAttrs['selected'] = "selected"; |
78 | } |
79 | if ( |
80 | array_key_exists( 'value_labels', $other_args ) && |
81 | is_array( $other_args['value_labels'] ) && |
82 | array_key_exists( $possible_value, $other_args['value_labels'] ) |
83 | ) { |
84 | $label = $other_args['value_labels'][$possible_value]; |
85 | } else { |
86 | $label = $possible_value; |
87 | } |
88 | $innerDropdown .= Html::element( 'option', $optionAttrs, $label ); |
89 | } |
90 | $selectAttrs = [ |
91 | 'id' => $input_id, |
92 | 'tabindex' => $wgPageFormsTabIndex, |
93 | 'name' => $input_name, |
94 | 'class' => $className |
95 | ]; |
96 | if ( $is_disabled ) { |
97 | $selectAttrs['disabled'] = 'disabled'; |
98 | } |
99 | if ( array_key_exists( 'origName', $other_args ) ) { |
100 | $selectAttrs['origname'] = $other_args['origName']; |
101 | } |
102 | $text = Html::rawElement( 'select', $selectAttrs, $innerDropdown ); |
103 | $spanClass = 'inputSpan'; |
104 | if ( $is_mandatory ) { |
105 | $spanClass .= ' mandatoryFieldSpan'; |
106 | } |
107 | $text = Html::rawElement( 'span', [ 'class' => $spanClass ], $text ); |
108 | return $text; |
109 | } |
110 | |
111 | /** |
112 | * Returns the HTML code to be included in the output page for this input. |
113 | * @return string |
114 | */ |
115 | public function getHtmlText(): string { |
116 | return self::getHTML( |
117 | $this->mCurrentValue, |
118 | $this->mInputName, |
119 | $this->mIsMandatory, |
120 | $this->mIsDisabled, |
121 | $this->mOtherArgs |
122 | ); |
123 | } |
124 | } |