| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * @since 2.04 |
| 13 | 13 | * |
| 14 | - * @var stdClass | |
| 14 | + * @var stdClass|null | |
| 15 | 15 | */ |
| 16 | - protected $field = null; | |
| 16 | + protected $field; | |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * @since 4.03 |
| 20 | 20 | * |
| @@ -55,9 +55,9 @@ | ||
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | $this->entry = $entry; |
| 58 | 58 | $this->entry_id = $entry->id; |
| 59 | - $field = apply_filters( 'frm_field_value_object', $field ); | |
| 59 | + $field = apply_filters( 'frm_field_value_object', $field ); | |
| 60 | 60 | $this->field = $field; |
| 61 | 61 | $this->init_saved_value( $entry ); |
| 62 | 62 | } |
| 63 | 63 | |
| @@ -64,8 +64,9 @@ | ||
| 64 | 64 | /** |
| 65 | 65 | * Gets entry property. |
| 66 | 66 | * |
| 67 | 67 | * @since 5.0.16 |
| 68 | + * | |
| 68 | 69 | * @return stdClass |
| 69 | 70 | */ |
| 70 | 71 | public function get_entry() { |
| 71 | 72 | return $this->entry; |
| @@ -102,9 +103,10 @@ | ||
| 102 | 103 | * @return void |
| 103 | 104 | */ |
| 104 | 105 | public function prepare_displayed_value( $atts = array() ) { |
| 105 | 106 | $this->displayed_value = $this->saved_value; |
| 106 | - unset( $atts['class'] ); // This class shouldn't affect values. | |
| 107 | + // This class shouldn't affect values. | |
| 108 | + unset( $atts['class'] ); | |
| 107 | 109 | $this->generate_displayed_value_for_field_type( $atts ); |
| 108 | 110 | $this->filter_displayed_value( $atts ); |
| 109 | 111 | } |
| 110 | 112 | |
| @@ -113,8 +115,10 @@ | ||
| 113 | 115 | * |
| 114 | 116 | * @since 2.05.06 |
| 115 | 117 | * |
| 116 | 118 | * @param string $value |
| 119 | + * | |
| 120 | + * @return mixed | |
| 117 | 121 | */ |
| 118 | 122 | public function get_field_option( $value ) { |
| 119 | 123 | return FrmField::get_option( $this->field, $value ); |
| 120 | 124 | } |
| @@ -122,8 +126,10 @@ | ||
| 122 | 126 | /** |
| 123 | 127 | * @since 4.03 |
| 124 | 128 | * |
| 125 | 129 | * @param string $option |
| 130 | + * | |
| 131 | + * @return mixed | |
| 126 | 132 | */ |
| 127 | 133 | public function get_field_attr( $option ) { |
| 128 | 134 | return is_object( $this->field ) ? $this->field->{$option} : ''; |
| 129 | 135 | } |
| @@ -140,8 +146,10 @@ | ||
| 140 | 146 | /** |
| 141 | 147 | * Get the field property's label |
| 142 | 148 | * |
| 143 | 149 | * @since 2.04 |
| 150 | + * | |
| 151 | + * @return string | |
| 144 | 152 | */ |
| 145 | 153 | public function get_field_label() { |
| 146 | 154 | return $this->get_field_attr( 'name' ); |
| 147 | 155 | } |
| @@ -149,8 +157,10 @@ | ||
| 149 | 157 | /** |
| 150 | 158 | * Get the field property's id |
| 151 | 159 | * |
| 152 | 160 | * @since 2.05 |
| 161 | + * | |
| 162 | + * @return string | |
| 153 | 163 | */ |
| 154 | 164 | public function get_field_id() { |
| 155 | 165 | return $this->get_field_attr( 'id' ); |
| 156 | 166 | } |
| @@ -158,8 +168,10 @@ | ||
| 158 | 168 | /** |
| 159 | 169 | * Get the field property's key |
| 160 | 170 | * |
| 161 | 171 | * @since 2.04 |
| 172 | + * | |
| 173 | + * @return string | |
| 162 | 174 | */ |
| 163 | 175 | public function get_field_key() { |
| 164 | 176 | return $this->get_field_attr( 'field_key' ); |
| 165 | 177 | } |
| @@ -167,8 +179,10 @@ | ||
| 167 | 179 | /** |
| 168 | 180 | * Get the field property's type |
| 169 | 181 | * |
| 170 | 182 | * @since 2.04 |
| 183 | + * | |
| 184 | + * @return string | |
| 171 | 185 | */ |
| 172 | 186 | public function get_field_type() { |
| 173 | 187 | return $this->get_field_attr( 'type' ); |
| 174 | 188 | } |
| @@ -176,8 +190,10 @@ | ||
| 176 | 190 | /** |
| 177 | 191 | * Get the saved_value property |
| 178 | 192 | * |
| 179 | 193 | * @since 2.04 |
| 194 | + * | |
| 195 | + * @return mixed | |
| 180 | 196 | */ |
| 181 | 197 | public function get_saved_value() { |
| 182 | 198 | return $this->saved_value; |
| 183 | 199 | } |
| @@ -185,8 +201,10 @@ | ||
| 185 | 201 | /** |
| 186 | 202 | * Get the displayed_value property |
| 187 | 203 | * |
| 188 | 204 | * @since 2.04 |
| 205 | + * | |
| 206 | + * @return mixed | |
| 189 | 207 | */ |
| 190 | 208 | public function get_displayed_value() { |
| 191 | 209 | if ( $this->displayed_value === 'frm_not_prepared' ) { |
| 192 | 210 | return __( 'The display value has not been prepared. Please use the prepare_display_value() method before calling get_displayed_value().', 'formidable' ); |
| @@ -204,13 +222,14 @@ | ||
| 204 | 222 | * |
| 205 | 223 | * @return void |
| 206 | 224 | */ |
| 207 | 225 | protected function generate_displayed_value_for_field_type( $atts ) { |
| 208 | - if ( ! FrmAppHelper::is_empty_value( $this->displayed_value, '' ) ) { | |
| 209 | - $field_obj = FrmFieldFactory::get_field_object( $this->field ); | |
| 226 | + if ( FrmAppHelper::is_empty_value( $this->displayed_value, '' ) ) { | |
| 227 | + return; | |
| 228 | + } | |
| 210 | 229 | |
| 211 | - $this->displayed_value = $field_obj->get_display_value( $this->displayed_value, $atts ); | |
| 212 | - } | |
| 230 | + $field_obj = FrmFieldFactory::get_field_object( $this->field ); | |
| 231 | + $this->displayed_value = $field_obj->get_display_value( $this->displayed_value, $atts ); | |
| 213 | 232 | } |
| 214 | 233 | |
| 215 | 234 | /** |
| 216 | 235 | * Filter the displayed_value property |
| @@ -223,37 +242,14 @@ | ||
| 223 | 242 | */ |
| 224 | 243 | protected function filter_displayed_value( $atts ) { |
| 225 | 244 | if ( ! is_object( $this->entry ) || empty( $this->entry->metas ) ) { |
| 226 | 245 | $this->entry = FrmEntry::getOne( $this->entry_id, true ); |
| 246 | + | |
| 227 | 247 | if ( ! is_object( $this->entry ) ) { |
| 228 | 248 | return; |
| 229 | 249 | } |
| 230 | 250 | } |
| 231 | 251 | |
| 232 | - // TODO: maybe change from 'source' to 'run_filters' = 'email' | |
| 233 | - if ( isset( $atts['source'] ) && $atts['source'] === 'entry_formatter' ) { | |
| 234 | - // Deprecated frm_email_value hook | |
| 235 | - $meta = array( | |
| 236 | - 'item_id' => $this->entry->id, | |
| 237 | - 'field_id' => $this->field->id, | |
| 238 | - 'meta_value' => $this->saved_value, | |
| 239 | - 'field_type' => $this->field->type, | |
| 240 | - ); | |
| 241 | - | |
| 242 | - if ( has_filter( 'frm_email_value' ) ) { | |
| 243 | - _deprecated_function( 'The frm_email_value filter', '2.04', 'the frm_display_{fieldtype}_value_custom filter' ); | |
| 244 | - $this->displayed_value = apply_filters( | |
| 245 | - 'frm_email_value', | |
| 246 | - $this->displayed_value, | |
| 247 | - (object) $meta, | |
| 248 | - $this->entry, | |
| 249 | - array( | |
| 250 | - 'field' => $this->field, | |
| 251 | - ) | |
| 252 | - ); | |
| 253 | - } | |
| 254 | - } | |
| 255 | - | |
| 256 | 252 | // frm_display_{fieldtype}_value_custom hook |
| 257 | 253 | $this->displayed_value = apply_filters( |
| 258 | 254 | 'frm_display_' . $this->field->type . '_value_custom', |
| 259 | 255 | $this->displayed_value, |
| @@ -273,16 +269,18 @@ | ||
| 273 | 269 | * |
| 274 | 270 | * @return void |
| 275 | 271 | */ |
| 276 | 272 | protected function clean_saved_value() { |
| 277 | - if ( $this->saved_value !== '' ) { | |
| 278 | - if ( ! is_array( $this->saved_value ) && ! is_object( $this->saved_value ) ) { | |
| 279 | - $field_type = FrmField::get_field_type( $this->field ); | |
| 280 | - FrmFieldsHelper::prepare_field_value( $this->saved_value, $field_type ); | |
| 281 | - } | |
| 273 | + if ( $this->saved_value === '' ) { | |
| 274 | + return; | |
| 275 | + } | |
| 282 | 276 | |
| 283 | - if ( is_array( $this->saved_value ) && empty( $this->saved_value ) ) { | |
| 284 | - $this->saved_value = ''; | |
| 285 | - } | |
| 277 | + if ( ! is_array( $this->saved_value ) && ! is_object( $this->saved_value ) ) { | |
| 278 | + $field_type = FrmField::get_field_type( $this->field ); | |
| 279 | + FrmFieldsHelper::prepare_field_value( $this->saved_value, $field_type ); | |
| 280 | + } | |
| 281 | + | |
| 282 | + if ( is_array( $this->saved_value ) && ! $this->saved_value ) { | |
| 283 | + $this->saved_value = ''; | |
| 286 | 284 | } |
| 287 | 285 | } |
| 288 | 286 | } |