date-field-parser.php
4 years ago
datetime-field-parser.php
4 years ago
datetime-trait.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
39 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 get_response() { |
| 16 | $string_value = wp_unslash( wp_specialchars_decode( $this->value, ENT_COMPAT ) ); |
| 17 | $value = json_decode( $string_value, true ); |
| 18 | |
| 19 | if ( $this->is_value_format( 'id' ) ) { |
| 20 | if ( ! is_array( $value ) ) { |
| 21 | $value = ! empty( $value ) ? absint( $value ) : null; |
| 22 | } else { |
| 23 | $value = implode( ',', $value ); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | if ( is_array( $value ) && $this->is_value_format( 'url' ) ) { |
| 28 | $value = implode( ', ', $value ); |
| 29 | } |
| 30 | |
| 31 | return $value; |
| 32 | } |
| 33 | |
| 34 | private function is_value_format( $format ) { |
| 35 | return ( ! empty( $this->settings['insert_attachment'] ) |
| 36 | && ! empty( $this->settings['value_format'] ) |
| 37 | && $format === $this->settings['value_format'] ); |
| 38 | } |
| 39 | } |