| @@ -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; |
| @@ -77,10 +76,8 @@ | ||
| 77 | 76 | * |
| 78 | 77 | * @since 2.04 |
| 79 | 78 | * |
| 80 | 79 | * @param stdClass $entry |
| 81 | - * | |
| 82 | - * @return void | |
| 83 | 80 | */ |
| 84 | 81 | protected function init_saved_value( $entry ) { |
| 85 | 82 | if ( $this->field->type === 'html' ) { |
| 86 | 83 | $this->saved_value = $this->field->description; |
| @@ -98,15 +95,12 @@ | ||
| 98 | 95 | * |
| 99 | 96 | * @since 2.05 |
| 100 | 97 | * |
| 101 | 98 | * @param array $atts |
| 102 | - * | |
| 103 | - * @return void | |
| 104 | 99 | */ |
| 105 | 100 | public function prepare_displayed_value( $atts = array() ) { |
| 106 | 101 | $this->displayed_value = $this->saved_value; |
| 107 | - // This class shouldn't affect values. | |
| 108 | - unset( $atts['class'] ); | |
| 102 | + unset( $atts['class'] ); // This class shouldn't affect values. | |
| 109 | 103 | $this->generate_displayed_value_for_field_type( $atts ); |
| 110 | 104 | $this->filter_displayed_value( $atts ); |
| 111 | 105 | } |
| 112 | 106 | |
| @@ -113,12 +107,8 @@ | ||
| 113 | 107 | /** |
| 114 | 108 | * Get a value from the field settings |
| 115 | 109 | * |
| 116 | 110 | * @since 2.05.06 |
| 117 | - * | |
| 118 | - * @param string $value | |
| 119 | - * | |
| 120 | - * @return mixed | |
| 121 | 111 | */ |
| 122 | 112 | public function get_field_option( $value ) { |
| 123 | 113 | return FrmField::get_option( $this->field, $value ); |
| 124 | 114 | } |
| @@ -124,12 +114,8 @@ | ||
| 124 | 114 | } |
| 125 | 115 | |
| 126 | 116 | /** |
| 127 | 117 | * @since 4.03 |
| 128 | - * | |
| 129 | - * @param string $option | |
| 130 | - * | |
| 131 | - * @return mixed | |
| 132 | 118 | */ |
| 133 | 119 | public function get_field_attr( $option ) { |
| 134 | 120 | return is_object( $this->field ) ? $this->field->{$option} : ''; |
| 135 | 121 | } |
| @@ -135,10 +121,8 @@ | ||
| 135 | 121 | } |
| 136 | 122 | |
| 137 | 123 | /** |
| 138 | 124 | * @since 4.03 |
| 139 | - * | |
| 140 | - * @return stdClass | |
| 141 | 125 | */ |
| 142 | 126 | public function get_field() { |
| 143 | 127 | return $this->field; |
| 144 | 128 | } |
| @@ -146,10 +130,8 @@ | ||
| 146 | 130 | /** |
| 147 | 131 | * Get the field property's label |
| 148 | 132 | * |
| 149 | 133 | * @since 2.04 |
| 150 | - * | |
| 151 | - * @return string | |
| 152 | 134 | */ |
| 153 | 135 | public function get_field_label() { |
| 154 | 136 | return $this->get_field_attr( 'name' ); |
| 155 | 137 | } |
| @@ -157,10 +139,8 @@ | ||
| 157 | 139 | /** |
| 158 | 140 | * Get the field property's id |
| 159 | 141 | * |
| 160 | 142 | * @since 2.05 |
| 161 | - * | |
| 162 | - * @return string | |
| 163 | 143 | */ |
| 164 | 144 | public function get_field_id() { |
| 165 | 145 | return $this->get_field_attr( 'id' ); |
| 166 | 146 | } |
| @@ -168,10 +148,8 @@ | ||
| 168 | 148 | /** |
| 169 | 149 | * Get the field property's key |
| 170 | 150 | * |
| 171 | 151 | * @since 2.04 |
| 172 | - * | |
| 173 | - * @return string | |
| 174 | 152 | */ |
| 175 | 153 | public function get_field_key() { |
| 176 | 154 | return $this->get_field_attr( 'field_key' ); |
| 177 | 155 | } |
| @@ -179,10 +157,8 @@ | ||
| 179 | 157 | /** |
| 180 | 158 | * Get the field property's type |
| 181 | 159 | * |
| 182 | 160 | * @since 2.04 |
| 183 | - * | |
| 184 | - * @return string | |
| 185 | 161 | */ |
| 186 | 162 | public function get_field_type() { |
| 187 | 163 | return $this->get_field_attr( 'type' ); |
| 188 | 164 | } |
| @@ -190,10 +166,8 @@ | ||
| 190 | 166 | /** |
| 191 | 167 | * Get the saved_value property |
| 192 | 168 | * |
| 193 | 169 | * @since 2.04 |
| 194 | - * | |
| 195 | - * @return mixed | |
| 196 | 170 | */ |
| 197 | 171 | public function get_saved_value() { |
| 198 | 172 | return $this->saved_value; |
| 199 | 173 | } |
| @@ -201,10 +175,8 @@ | ||
| 201 | 175 | /** |
| 202 | 176 | * Get the displayed_value property |
| 203 | 177 | * |
| 204 | 178 | * @since 2.04 |
| 205 | - * | |
| 206 | - * @return mixed | |
| 207 | 179 | */ |
| 208 | 180 | public function get_displayed_value() { |
| 209 | 181 | if ( $this->displayed_value === 'frm_not_prepared' ) { |
| 210 | 182 | return __( 'The display value has not been prepared. Please use the prepare_display_value() method before calling get_displayed_value().', 'formidable' ); |
| @@ -222,14 +194,13 @@ | ||
| 222 | 194 | * |
| 223 | 195 | * @return void |
| 224 | 196 | */ |
| 225 | 197 | protected function generate_displayed_value_for_field_type( $atts ) { |
| 226 | - if ( FrmAppHelper::is_empty_value( $this->displayed_value, '' ) ) { | |
| 227 | - return; | |
| 198 | + if ( ! FrmAppHelper::is_empty_value( $this->displayed_value, '' ) ) { | |
| 199 | + $field_obj = FrmFieldFactory::get_field_object( $this->field ); | |
| 200 | + | |
| 201 | + $this->displayed_value = $field_obj->get_display_value( $this->displayed_value, $atts ); | |
| 228 | 202 | } |
| 229 | - | |
| 230 | - $field_obj = FrmFieldFactory::get_field_object( $this->field ); | |
| 231 | - $this->displayed_value = $field_obj->get_display_value( $this->displayed_value, $atts ); | |
| 232 | 203 | } |
| 233 | 204 | |
| 234 | 205 | /** |
| 235 | 206 | * Filter the displayed_value property |
| @@ -236,20 +207,41 @@ | ||
| 236 | 207 | * |
| 237 | 208 | * @since 2.04 |
| 238 | 209 | * |
| 239 | 210 | * @param array $atts |
| 240 | - * | |
| 241 | - * @return void | |
| 242 | 211 | */ |
| 243 | 212 | protected function filter_displayed_value( $atts ) { |
| 244 | 213 | if ( ! is_object( $this->entry ) || empty( $this->entry->metas ) ) { |
| 245 | 214 | $this->entry = FrmEntry::getOne( $this->entry_id, true ); |
| 246 | - | |
| 247 | 215 | if ( ! is_object( $this->entry ) ) { |
| 248 | 216 | return; |
| 249 | 217 | } |
| 250 | 218 | } |
| 251 | 219 | |
| 220 | + // TODO: maybe change from 'source' to 'run_filters' = 'email' | |
| 221 | + if ( isset( $atts['source'] ) && $atts['source'] === 'entry_formatter' ) { | |
| 222 | + // Deprecated frm_email_value hook | |
| 223 | + $meta = array( | |
| 224 | + 'item_id' => $this->entry->id, | |
| 225 | + 'field_id' => $this->field->id, | |
| 226 | + 'meta_value' => $this->saved_value, | |
| 227 | + 'field_type' => $this->field->type, | |
| 228 | + ); | |
| 229 | + | |
| 230 | + if ( has_filter( 'frm_email_value' ) ) { | |
| 231 | + _deprecated_function( 'The frm_email_value filter', '2.04', 'the frm_display_{fieldtype}_value_custom filter' ); | |
| 232 | + $this->displayed_value = apply_filters( | |
| 233 | + 'frm_email_value', | |
| 234 | + $this->displayed_value, | |
| 235 | + (object) $meta, | |
| 236 | + $this->entry, | |
| 237 | + array( | |
| 238 | + 'field' => $this->field, | |
| 239 | + ) | |
| 240 | + ); | |
| 241 | + } | |
| 242 | + } | |
| 243 | + | |
| 252 | 244 | // frm_display_{fieldtype}_value_custom hook |
| 253 | 245 | $this->displayed_value = apply_filters( |
| 254 | 246 | 'frm_display_' . $this->field->type . '_value_custom', |
| 255 | 247 | $this->displayed_value, |
| @@ -262,25 +254,20 @@ | ||
| 262 | 254 | $this->displayed_value = apply_filters( 'frm_display_value', $this->displayed_value, $this->field, $atts ); |
| 263 | 255 | } |
| 264 | 256 | |
| 265 | 257 | /** |
| 266 | - * Clean a field's saved value. | |
| 258 | + * Clean a field's saved value | |
| 267 | 259 | * |
| 268 | 260 | * @since 2.04 |
| 269 | - * | |
| 270 | - * @return void | |
| 271 | 261 | */ |
| 272 | 262 | protected function clean_saved_value() { |
| 273 | - if ( $this->saved_value === '' ) { | |
| 274 | - return; | |
| 275 | - } | |
| 263 | + if ( $this->saved_value !== '' ) { | |
| 264 | + if ( ! is_array( $this->saved_value ) && ! is_object( $this->saved_value ) ) { | |
| 265 | + FrmAppHelper::unserialize_or_decode( $this->saved_value ); | |
| 266 | + } | |
| 276 | 267 | |
| 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 = ''; | |
| 268 | + if ( is_array( $this->saved_value ) && empty( $this->saved_value ) ) { | |
| 269 | + $this->saved_value = ''; | |
| 270 | + } | |
| 284 | 271 | } |
| 285 | 272 | } |
| 286 | 273 | } |