PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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 +53 -12 6.4 → trunk View file →
@@ -25,13 +25,13 @@
25 25 */
26 26 protected $field_key = '';
27 27
28 28 /**
29 - * @var null
29 + * @var FrmProFieldSettings|null
30 30 *
31 31 * @since 2.03.05
32 32 */
33 - protected $field_settings = null;
33 + protected $field_settings;
34 34
35 35 /**
36 36 * @var array
37 37 *
@@ -67,25 +67,37 @@
67 67 */
68 68 protected $blank_option_label = '';
69 69
70 70 /**
71 - * @var object
71 + * @var object|null
72 72 *
73 73 * @since 2.03.05
74 74 */
75 - protected $db_row = null;
75 + protected $db_row;
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 + /**
78 87 * FrmFieldValueSelector constructor
79 88 *
80 - * @param int|string $field_id
89 + * @param int|string $field_id Field ID.
90 + * @param array $args Arguments for configuring the value selector.
81 91 */
82 92 public function __construct( $field_id, $args ) {
83 93 $this->set_html_name( $args );
84 94 $this->set_value( $args );
85 95 $this->set_source( $args );
96 + $this->set_truncate( $args );
86 97
87 98 $this->field_id = (int) $field_id;
99 +
88 100 if ( $this->field_id === 0 ) {
89 101 return;
90 102 }
91 103
@@ -90,13 +102,15 @@
90 102 }
91 103
92 104 $this->set_db_row();
93 105
94 - if ( $this->has_db_row() ) {
95 - $this->set_field_key();
96 - $this->set_field_settings();
97 - $this->set_options();
106 + if ( ! $this->has_db_row() ) {
107 + return;
98 108 }
109 +
110 + $this->set_field_key();
111 + $this->set_field_settings();
112 + $this->set_options();
99 113 }
100 114
101 115 /**
102 116 * Set the db_row property
@@ -196,8 +210,21 @@
196 210 }
197 211 }
198 212
199 213 /**
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 + /**
200 227 * Check if object has any options
201 228 *
202 229 * @since 2.03.05
203 230 *
@@ -252,22 +279,36 @@
252 279 * @return void
253 280 */
254 281 protected function display_dropdown() {
255 282 echo '<select name="' . esc_attr( $this->html_name ) . '">';
256 - echo '<option value="">' . esc_attr( $this->blank_option_label ) . '</option>';
283 + echo '<option value="">' . esc_html( $this->blank_option_label ) . '</option>';
257 284
258 - if ( ! empty( $this->options ) ) {
285 + if ( $this->options ) {
286 + $truncate = $this->truncate ?? 25;
287 +
259 288 foreach ( $this->options as $key => $value ) {
289 + // phpcs:ignore Universal.Operators.StrictComparisons
260 290 if ( $value == '' ) {
261 291 continue;
262 292 }
263 293
264 294 $option = $this->get_single_field_option( $key, $value );
265 - $option->print_single_option( $this->value, 25 );
295 + $option->print_single_option( $this->value, $truncate, $this->use_value_as_label_in_dropdown() );
266 296 }
267 297 }
268 298
269 299 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;
270 311 }
271 312
272 313 /**
273 314 * Get an instance of FrmFieldOption