PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.5.4
JetFormBuilder — Dynamic Blocks Form Builder v3.5.4
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / block-parsers / fields / media-field-parser.php
jetformbuilder / modules / block-parsers / fields Last commit date
date-field-parser.php 2 years ago datetime-field-parser.php 2 years ago datetime-trait.php 2 years ago default-parser.php 2 years ago hidden-field-parser.php 2 years ago media-field-parser.php 1 year ago repeater-field-parser.php 2 years ago text-field-parser.php 2 years ago wysiwyg-field-parser.php 2 years ago
media-field-parser.php
81 lines
1 <?php
2
3
4 namespace JFB_Modules\Block_Parsers\Fields;
5
6 use Jet_Form_Builder\Classes\Resources\Has_Error_File;
7 use Jet_Form_Builder\Classes\Resources\Media_Block_Value;
8 use Jet_Form_Builder\Exceptions\Request_Exception;
9 use Jet_Form_Builder\Request\Exceptions\Sanitize_Value_Exception;
10 use Jet_Form_Builder\Classes\Resources\Upload_Exception;
11 use JFB_Modules\Block_Parsers\Field_Data_Parser;
12 use JFB_Modules\Block_Parsers\File_Uploader;
13
14 // If this file is called directly, abort.
15 if ( ! defined( 'WPINC' ) ) {
16 die;
17 }
18
19 class Media_Field_Parser extends Field_Data_Parser {
20
21 public function type() {
22 return 'media-field';
23 }
24
25 /**
26 * @since 3.0.4 Added `jet-form-builder/media-field/before-upload` hook
27 *
28 * @return array|false|int|string|null
29 * @throws Sanitize_Value_Exception
30 */
31 public function get_response() {
32 if (
33 empty( $this->get_file() ) ||
34 (
35 is_object( $this->get_file() ) &&
36 is_a( $this->get_file(), Has_Error_File::class ) &&
37 $this->get_file()->has_error()
38 )
39 ) {
40 /**
41 * We should leave here $this->value for case, while this field exporting
42 * with values from Form Record
43 *
44 * @see https://github.com/Crocoblock/issues-tracker/issues/4422
45 */
46 return $this->value;
47 }
48 do_action( 'jet-form-builder/media-field/before-upload', $this );
49
50 $uploader = ( new File_Uploader() )->set_context( $this );
51
52 try {
53 /** @var Media_Block_Value $uploads */
54 $uploads = $uploader->upload();
55 } catch ( Upload_Exception $exception ) {
56 $this->collect_error( $exception->getMessage() );
57 return false;
58 }
59
60 $this->set_file( $uploads );
61
62 switch ( $this->get_value_format() ) {
63 case 'id':
64 return $uploads->get_attachment_id();
65 case 'both':
66 return $uploads->get_attachment_both();
67 case 'ids':
68 return $uploads->get_attachment_ids();
69 default:
70 return $uploads->get_attachment_url();
71 }
72 }
73
74 protected function get_value_format(): string {
75 return empty( $this->settings['insert_attachment'] )
76 ? 'url'
77 : ( $this->settings['value_format'] ?? 'url' );
78 }
79
80 }
81