date-field-parser.php
4 years ago
datetime-field-parser.php
4 years ago
datetime-trait.php
4 years ago
hidden-field-parser.php
4 years ago
media-field-parser.php
4 years ago
repeater-field-parser.php
4 years ago
text-field-parser.php
4 years ago
wysiwyg-field-parser.php
4 years ago
media-field-parser.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Request\Fields; |
| 5 | |
| 6 | use Jet_Form_Builder\Exceptions\Request_Exception; |
| 7 | use Jet_Form_Builder\Request\Field_Data_Parser; |
| 8 | |
| 9 | class Media_Field_Parser extends Field_Data_Parser { |
| 10 | |
| 11 | public function type() { |
| 12 | return 'media-field'; |
| 13 | } |
| 14 | |
| 15 | public function parse_value( $value ) { |
| 16 | $string_value = wp_unslash( wp_specialchars_decode( $value, ENT_COMPAT ) ); |
| 17 | |
| 18 | return json_decode( $string_value, true ); |
| 19 | } |
| 20 | |
| 21 | public function get_response() { |
| 22 | if ( $this->is_value_format( 'id' ) ) { |
| 23 | if ( ! is_array( $this->value ) ) { |
| 24 | $this->value = ! empty( $this->value ) ? absint( $this->value ) : null; |
| 25 | } else { |
| 26 | $this->value = implode( ',', $this->value ); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | if ( is_array( $this->value ) && $this->is_value_format( 'url' ) ) { |
| 31 | $this->value = implode( ', ', $this->value ); |
| 32 | } |
| 33 | |
| 34 | return $this->value; |
| 35 | } |
| 36 | |
| 37 | private function is_value_format( $format ) { |
| 38 | return ( ! empty( $this->settings['insert_attachment'] ) |
| 39 | && ! empty( $this->settings['value_format'] ) |
| 40 | && $format === $this->settings['value_format'] ); |
| 41 | } |
| 42 | } |
| 43 |