PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.5
JetFormBuilder — Dynamic Blocks Form Builder v3.6.5
3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.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 1 week ago hidden-field-parser.php 3 weeks ago media-field-parser.php 1 week ago repeater-field-parser.php 1 week ago text-field-parser.php 2 years ago wysiwyg-field-parser.php 2 years ago
media-field-parser.php
85 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 protected function allows_array_value(): bool {
26 return true;
27 }
28
29 /**
30 * @since 3.0.4 Added `jet-form-builder/media-field/before-upload` hook
31 *
32 * @return array|false|int|string|null
33 * @throws Sanitize_Value_Exception
34 */
35 public function get_response() {
36 if (
37 empty( $this->get_file() ) ||
38 (
39 is_object( $this->get_file() ) &&
40 is_a( $this->get_file(), Has_Error_File::class ) &&
41 $this->get_file()->has_error()
42 )
43 ) {
44 /**
45 * We should leave here $this->value for case, while this field exporting
46 * with values from Form Record
47 *
48 * @see https://github.com/Crocoblock/issues-tracker/issues/4422
49 */
50 return $this->value;
51 }
52 do_action( 'jet-form-builder/media-field/before-upload', $this );
53
54 $uploader = ( new File_Uploader() )->set_context( $this );
55
56 try {
57 /** @var Media_Block_Value $uploads */
58 $uploads = $uploader->upload();
59 } catch ( Upload_Exception $exception ) {
60 $this->collect_error( $exception->getMessage() );
61 return false;
62 }
63
64 $this->set_file( $uploads );
65
66 switch ( $this->get_value_format() ) {
67 case 'id':
68 return $uploads->get_attachment_id();
69 case 'both':
70 return $uploads->get_attachment_both();
71 case 'ids':
72 return $uploads->get_attachment_ids();
73 default:
74 return $uploads->get_attachment_url();
75 }
76 }
77
78 protected function get_value_format(): string {
79 return empty( $this->settings['insert_attachment'] )
80 ? 'url'
81 : ( $this->settings['value_format'] ?? 'url' );
82 }
83
84 }
85