PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.1
JetFormBuilder — Dynamic Blocks Form Builder v2.1.1
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 / includes / request / parser-context.php
jetformbuilder / includes / request Last commit date
exceptions 3 years ago fields 3 years ago field-data-parser.php 3 years ago file-uploader.php 3 years ago form-request-router.php 3 years ago parser-context.php 3 years ago parser-manager.php 3 years ago request-handler.php 3 years ago request-router.php 3 years ago
parser-context.php
156 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Request;
5
6 use Jet_Form_Builder\Blocks\Block_Helper;
7 use Jet_Form_Builder\Blocks\Types\Base;
8 use Jet_Form_Builder\Exceptions\Parse_Exception;
9 use Jet_Form_Builder\Exceptions\Repository_Exception;
10
11 class Parser_Context {
12
13 protected $block;
14 protected $settings;
15 protected $name = '';
16 protected $field_type;
17
18 protected $request;
19 protected $files;
20
21 protected $inside_conditional = false;
22
23 protected $context = array();
24
25 /**
26 * @return mixed
27 */
28 public function get_file() {
29 return $this->files[ $this->name ] ?? false;
30 }
31
32 public function get_value() {
33 return $this->request[ $this->name ] ?? '';
34 }
35
36 public function isset_parser(): bool {
37 return Parser_Manager::instance()->isset_parser( $this->field_type );
38 }
39
40 /**
41 * @return Field_Data_Parser
42 * @throws Repository_Exception
43 */
44 public function get_parser(): Field_Data_Parser {
45 return Parser_Manager::instance()->get_parser( $this->field_type );
46 }
47
48 public function save_to_request() {
49 Parser_Manager::instance()->save_to_request( $this->name, $this->field_type, $this->settings );
50 }
51
52 /**
53 * @param array $field
54 *
55 * @return $this
56 * @throws Parse_Exception
57 */
58 public function set_field( array $field ): Parser_Context {
59 $this->validate_field( $field );
60
61 $this->block = $field;
62 $this->settings = $field['attrs'];
63 $this->name = $field['attrs']['name'] ?? 'field_name';
64 $this->field_type = Block_Helper::delete_namespace( $field['blockName'] );
65
66 return $this;
67 }
68
69 /**
70 * @param array $field
71 *
72 * @throws Parse_Exception
73 */
74 protected function validate_field( array $field ) {
75 if ( empty( $field['blockName'] ) ) {
76 throw new Parse_Exception( Parser_Manager::EMPTY_BLOCK_ERROR );
77 }
78
79 if ( empty( $field['innerBlocks'] ) ) {
80 return;
81 }
82
83 if ( strpos( $field['blockName'], 'conditional-block' ) ) {
84 throw new Parse_Exception( Parser_Manager::IS_CONDITIONAL, $field['innerBlocks'] );
85 }
86 if ( ! Parser_Manager::instance()->isset_parser( $field['blockName'] ) ) {
87 throw new Parse_Exception( Parser_Manager::NOT_FIELD_HAS_INNER, $field['innerBlocks'] );
88 }
89 }
90
91 public function get_default_value() {
92 /** @var Base $block */
93 $block = jet_form_builder()->blocks->get_field_by_name( $this->field_type );
94
95 // the exception will never be thrown
96 $block->set_block_data( $this->settings );
97 $block->set_context( $this->context );
98 $block->set_preset();
99
100 return $block->block_attrs['default'];
101 }
102
103 public function set_request_context( array $request ): Parser_Context {
104 $this->request = $request;
105
106 return $this;
107 }
108
109
110 public function set_files_context( $files ): Parser_Context {
111 $this->files = $files;
112
113 return $this;
114 }
115
116 /**
117 * @return mixed
118 */
119 public function get_files() {
120 return $this->files;
121 }
122
123 /**
124 * @return mixed
125 */
126 public function get_block() {
127 return $this->block;
128 }
129
130 /**
131 * @return mixed
132 */
133 public function get_settings() {
134 return $this->settings;
135 }
136
137 /**
138 * @return string
139 */
140 public function get_name(): string {
141 return $this->name;
142 }
143
144 public function is_inside_conditional(): bool {
145 return $this->inside_conditional;
146 }
147
148 public function set_inside_conditional( bool $inside_conditional ): Parser_Context {
149 $this->inside_conditional = $inside_conditional;
150
151 return $this;
152 }
153
154
155 }
156