PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.0
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmFieldValueSelector.php +12 -73 6.356.0 View file →
@@ -25,13 +25,13 @@
25 25 */
26 26 protected $field_key = '';
27 27
28 28 /**
29 - * @var FrmProFieldSettings|null
29 + * @var null
30 30 *
31 31 * @since 2.03.05
32 32 */
33 - protected $field_settings;
33 + protected $field_settings = null;
34 34
35 35 /**
36 36 * @var array
37 37 *
@@ -67,37 +67,25 @@
67 67 */
68 68 protected $blank_option_label = '';
69 69
70 70 /**
71 - * @var object|null
71 + * @var object
72 72 *
73 73 * @since 2.03.05
74 74 */
75 - protected $db_row;
75 + protected $db_row = null;
76 76
77 77 /**
78 - * Field dropdowns will truncate at 25 characters by default.
79 - *
80 - * @var int|null
81 - *
82 - * @since 6.16.2
83 - */
84 - protected $truncate;
85 -
86 - /**
87 78 * FrmFieldValueSelector constructor
88 79 *
89 - * @param int|string $field_id Field ID.
90 - * @param array $args Arguments for configuring the value selector.
80 + * @param int|string $field_id
91 81 */
92 82 public function __construct( $field_id, $args ) {
93 83 $this->set_html_name( $args );
94 84 $this->set_value( $args );
95 85 $this->set_source( $args );
96 - $this->set_truncate( $args );
97 86
98 87 $this->field_id = (int) $field_id;
99 -
100 88 if ( $this->field_id === 0 ) {
101 89 return;
102 90 }
103 91
@@ -102,15 +90,13 @@
102 90 }
103 91
104 92 $this->set_db_row();
105 93
106 - if ( ! $this->has_db_row() ) {
107 - return;
94 + if ( $this->has_db_row() ) {
95 + $this->set_field_key();
96 + $this->set_field_settings();
97 + $this->set_options();
108 98 }
109 -
110 - $this->set_field_key();
111 - $this->set_field_settings();
112 - $this->set_options();
113 99 }
114 100
115 101 /**
116 102 * Set the db_row property
@@ -115,10 +101,8 @@
115 101 /**
116 102 * Set the db_row property
117 103 *
118 104 * @since 2.03.05
119 - *
120 - * @return void
121 105 */
122 106 private function set_db_row() {
123 107 $where = array(
124 108 'id' => $this->field_id,
@@ -134,10 +118,8 @@
134 118 /**
135 119 * Set the field_key property
136 120 *
137 121 * @since 2.03.05
138 - *
139 - * @return void
140 122 */
141 123 private function set_field_key() {
142 124 $this->field_key = $this->db_row->field_key;
143 125 }
@@ -145,10 +127,8 @@
145 127 /**
146 128 * Set the field_settings property
147 129 *
148 130 * @since 2.03.05
149 - *
150 - * @return void
151 131 */
152 132 protected function set_field_settings() {
153 133 // Leave as null for free version
154 134 }
@@ -156,10 +136,8 @@
156 136 /**
157 137 * Set the options property
158 138 *
159 139 * @since 2.03.05
160 - *
161 - * @return void
162 140 */
163 141 protected function set_options() {
164 142 $field_obj = FrmFieldFactory::get_field_object( $this->db_row );
165 143 $this->options = $field_obj->get_options( array() );
@@ -170,10 +148,8 @@
170 148 *
171 149 * @since 2.03.05
172 150 *
173 151 * @param array $args
174 - *
175 - * @return void
176 152 */
177 153 protected function set_html_name( $args ) {
178 154 if ( isset( $args['html_name'] ) ) {
179 155 $this->html_name = (string) $args['html_name'];
@@ -185,10 +161,8 @@
185 161 *
186 162 * @since 2.03.05
187 163 *
188 164 * @param array $args
189 - *
190 - * @return void
191 165 */
192 166 protected function set_value( $args ) {
193 167 if ( isset( $args['value'] ) ) {
194 168 $this->value = (string) $args['value'];
@@ -200,10 +174,8 @@
200 174 *
201 175 * @since 2.03.05
202 176 *
203 177 * @param array $args
204 - *
205 - * @return void
206 178 */
207 179 protected function set_source( $args ) {
208 180 if ( isset( $args['source'] ) ) {
209 181 $this->source = (string) $args['source'];
@@ -210,21 +182,8 @@
210 182 }
211 183 }
212 184
213 185 /**
214 - * @since 6.16.2
215 - *
216 - * @param array $args
217 - *
218 - * @return void
219 - */
220 - protected function set_truncate( $args ) {
221 - if ( isset( $args['truncate'] ) && is_numeric( $args['truncate'] ) ) {
222 - $this->truncate = (int) $args['truncate'];
223 - }
224 - }
225 -
226 - /**
227 186 * Check if object has any options
228 187 *
229 188 * @since 2.03.05
230 189 *
@@ -248,10 +207,8 @@
248 207 /**
249 208 * Display the field value selector (dropdown or text field)
250 209 *
251 210 * @since 2.03.05
252 - *
253 - * @return void
254 211 */
255 212 public function display() {
256 213 if ( $this->has_options() ) {
257 214 $this->display_dropdown();
@@ -263,10 +220,8 @@
263 220 /**
264 221 * Print the field value text box
265 222 *
266 223 * @since 2.03.05
267 - *
268 - * @return void
269 224 */
270 225 public function display_text_box() {
271 226 echo '<input type="text" name="' . esc_attr( $this->html_name ) . '" value="' . esc_attr( trim( $this->value ) ) . '" />';
272 227 }
@@ -274,41 +229,25 @@
274 229 /**
275 230 * Display the field value selector
276 231 *
277 232 * @since 2.03.05
278 - *
279 - * @return void
280 233 */
281 234 protected function display_dropdown() {
282 235 echo '<select name="' . esc_attr( $this->html_name ) . '">';
283 - echo '<option value="">' . esc_html( $this->blank_option_label ) . '</option>';
236 + echo '<option value="">' . esc_attr( $this->blank_option_label ) . '</option>';
284 237
285 - if ( $this->options ) {
286 - $truncate = $this->truncate ?? 25;
287 -
238 + if ( ! empty( $this->options ) ) {
288 239 foreach ( $this->options as $key => $value ) {
289 - // phpcs:ignore Universal.Operators.StrictComparisons
290 240 if ( $value == '' ) {
291 241 continue;
292 242 }
293 243
294 244 $option = $this->get_single_field_option( $key, $value );
295 - $option->print_single_option( $this->value, $truncate, $this->use_value_as_label_in_dropdown() );
245 + $option->print_single_option( $this->value, 25 );
296 246 }
297 247 }
298 248
299 249 echo '</select>';
300 - }
301 -
302 - /**
303 - * Whether to use the field value as the option label in the dropdown when the label is empty.
304 - *
305 - * @since 6.25.1
306 - *
307 - * @return bool
308 - */
309 - protected function use_value_as_label_in_dropdown() {
310 - return false;
311 250 }
312 251
313 252 /**
314 253 * Get an instance of FrmFieldOption