| @@ -8,9 +8,9 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | class FrmFieldOption { |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * @var int|string | |
| 12 | + * @var string|int | |
| 13 | 13 | * |
| 14 | 14 | * @since 2.03.05 |
| 15 | 15 | */ |
| 16 | 16 | protected $option_key; |
| @@ -15,9 +15,9 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | protected $option_key; |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | - * @var array|string | |
| 19 | + * @var string|array | |
| 20 | 20 | * |
| 21 | 21 | * @since 2.03.05 |
| 22 | 22 | */ |
| 23 | 23 | protected $option; |
| @@ -23,9 +23,8 @@ | ||
| 23 | 23 | protected $option; |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @var string |
| 27 | - * | |
| 28 | 27 | * @since 2.03.05 |
| 29 | 28 | */ |
| 30 | 29 | protected $saved_value = ''; |
| 31 | 30 | |
| @@ -30,20 +29,12 @@ | ||
| 30 | 29 | protected $saved_value = ''; |
| 31 | 30 | |
| 32 | 31 | /** |
| 33 | 32 | * @var string |
| 34 | - * | |
| 35 | 33 | * @since 2.03.05 |
| 36 | 34 | */ |
| 37 | 35 | protected $option_label = ''; |
| 38 | 36 | |
| 39 | - /** | |
| 40 | - * @param int|string $option_key | |
| 41 | - * @param array|string $option | |
| 42 | - * @param array $args | |
| 43 | - * | |
| 44 | - * @return void | |
| 45 | - */ | |
| 46 | 37 | public function __construct( $option_key, $option, $args = array() ) { |
| 47 | 38 | $this->option_key = $option_key; |
| 48 | 39 | $this->option = $option; |
| 49 | 40 | $this->set_option_label(); |
| @@ -53,13 +44,15 @@ | ||
| 53 | 44 | /** |
| 54 | 45 | * Set the option label |
| 55 | 46 | * |
| 56 | 47 | * @since 2.03.05 |
| 57 | - * | |
| 58 | - * @return void | |
| 59 | 48 | */ |
| 60 | 49 | private function set_option_label() { |
| 61 | - $this->option_label = is_array( $this->option ) ? ( $this->option['label'] ?? reset( $this->option ) ) : $this->option; | |
| 50 | + if ( is_array( $this->option ) ) { | |
| 51 | + $this->option_label = ( isset( $this->option['label'] ) ? $this->option['label'] : reset( $this->option ) ); | |
| 52 | + } else { | |
| 53 | + $this->option_label = $this->option; | |
| 54 | + } | |
| 62 | 55 | } |
| 63 | 56 | |
| 64 | 57 | /** |
| 65 | 58 | * Set the saved value |
| @@ -64,10 +57,8 @@ | ||
| 64 | 57 | /** |
| 65 | 58 | * Set the saved value |
| 66 | 59 | * |
| 67 | 60 | * @since 2.03.05 |
| 68 | - * | |
| 69 | - * @return void | |
| 70 | 61 | */ |
| 71 | 62 | protected function set_saved_value() { |
| 72 | 63 | $this->saved_value = $this->option_label; |
| 73 | 64 | } |
| @@ -76,28 +67,17 @@ | ||
| 76 | 67 | * Print a single option |
| 77 | 68 | * |
| 78 | 69 | * @since 2.03.05 |
| 79 | 70 | * |
| 80 | - * @param string $selected_value The value of the option to be selected. | |
| 81 | - * @param int $truncate Truncate the option label if true. | |
| 82 | - * @param bool $use_value_as_label Use the option value as the label if true. | |
| 83 | - * | |
| 84 | - * @return void | |
| 71 | + * @param string $selected_value | |
| 72 | + * @param int $truncate | |
| 85 | 73 | */ |
| 86 | - public function print_single_option( $selected_value, $truncate, $use_value_as_label = false ) { | |
| 87 | - if ( '' === $this->saved_value && ! $use_value_as_label ) { | |
| 88 | - return; | |
| 74 | + public function print_single_option( $selected_value, $truncate ) { | |
| 75 | + if ( '' !== $this->saved_value ) { | |
| 76 | + echo '<option value="' . esc_attr( $this->saved_value ) . '"'; | |
| 77 | + selected( esc_attr( $selected_value ), esc_attr( $this->saved_value ) ); | |
| 78 | + // TODO: add hook that can add attributes to option text | |
| 79 | + echo '>'; | |
| 80 | + echo esc_html( FrmAppHelper::truncate( $this->option_label, $truncate ) ) . '</option>'; | |
| 89 | 81 | } |
| 90 | - | |
| 91 | - if ( $use_value_as_label && '' === trim( $this->option_label ) ) { | |
| 92 | - $label = '' !== $this->saved_value ? $this->saved_value : FrmAppHelper::get_no_label_text(); | |
| 93 | - } else { | |
| 94 | - $label = $this->option_label; | |
| 95 | - } | |
| 96 | - | |
| 97 | - echo '<option value="' . esc_attr( $this->saved_value ) . '"'; | |
| 98 | - selected( esc_attr( $selected_value ), esc_attr( $this->saved_value ) ); | |
| 99 | - // TODO: add hook that can add attributes to option text | |
| 100 | - echo '>'; | |
| 101 | - echo esc_html( FrmAppHelper::truncate( $label, $truncate ) ) . '</option>'; | |
| 102 | 82 | } |
| 103 | 83 | } |