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