PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.0
JetFormBuilder — Dynamic Blocks Form Builder v3.0.0
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 / classes / arguments / form-arguments.php
jetformbuilder / includes / classes / arguments Last commit date
default-form-arguments.php 3 years ago form-arguments.php 3 years ago
form-arguments.php
292 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Classes\Arguments;
5
6 use Jet_Form_Builder\Classes\Arrayable\Arrayable;
7 use Jet_Form_Builder\Classes\Tools;
8 use Jet_Form_Builder\Plugin;
9
10 /**
11 * @property int form_id
12 * @property string submit_type
13 * @property string required_mark
14 * @property string fields_layout
15 * @property bool enable_progress
16 * @property string fields_label_tag
17 * @property string load_nonce
18 * @property bool use_csrf
19 * @property string validation_type
20 * @property string clear
21 *
22 * Class Form_Arguments
23 * @package Jet_Form_Builder\Classes\Arguments
24 */
25 class Form_Arguments implements Arrayable {
26
27 const SETTER_PREFIX = 'set_';
28
29 public $props = array(
30 'form_id' => '',
31 'submit_type' => '',
32 'required_mark' => '',
33 'fields_layout' => '',
34 'enable_progress' => null,
35 'fields_label_tag' => '',
36 'load_nonce' => '',
37 'use_csrf' => '',
38 'validation_type' => '',
39 'clear' => '',
40 );
41
42 public function __construct( $form_id = 0 ) {
43 $this->set_form_id( (int) $form_id );
44 }
45
46 /**
47 * @param int|string $form_id
48 *
49 * @return Form_Arguments
50 */
51 public function set_form_id( $form_id ): Form_Arguments {
52 $this->form_id = $form_id;
53
54 return $this;
55 }
56
57 /**
58 * It turns out the inheritance of such an image
59 * Incoming Form Attributes (from block/widget/shortcode)
60 * (if not) -> Individual Form Arguments
61 * (if not) -> Default PHP Values
62 *
63 * @param array $block_attributes
64 *
65 * @return $this
66 */
67 public function load( array $block_attributes = array() ): Form_Arguments {
68 $jf_args = Plugin::instance()->post_type->get_args( $this->form_id );
69
70 $attributes_from_post_type = array_diff( $jf_args, $this->to_array() );
71 $form_block_or_widget = array_diff( $block_attributes, $this->to_array() );
72
73 /**
74 * @var $render_attributes array
75 */
76 $render_attributes = array_merge(
77 ...apply_filters(
78 'jet-form-builder/form-render/attributes',
79 array(
80 Default_Form_Arguments::arguments(),
81 $attributes_from_post_type,
82 $form_block_or_widget,
83 )
84 )
85 );
86
87 $this->set_from_array( $render_attributes );
88
89 return $this;
90 }
91
92 /**
93 * @param mixed $enable_progress
94 */
95 public function set_enable_progress( $enable_progress ) {
96 $this->enable_progress = (bool) $enable_progress;
97 }
98
99 /**
100 * @param null $clear
101 */
102 public function set_clear( $clear ) {
103 $this->clear = $clear;
104 }
105
106 /**
107 * @param null $use_csrf
108 */
109 public function set_use_csrf( $use_csrf ) {
110 $this->use_csrf = (bool) $use_csrf;
111 }
112
113 /**
114 * @param mixed $fields_label_tag
115 */
116 public function set_fields_label_tag( $fields_label_tag ) {
117 $fields_label_tag = strtolower( $fields_label_tag );
118
119 if ( ! in_array( $fields_label_tag, array( 'label', 'div' ), true ) ) {
120 return;
121 }
122
123 $this->fields_label_tag = $fields_label_tag;
124 }
125
126 /**
127 * @param mixed $fields_layout
128 */
129 public function set_fields_layout( $fields_layout ) {
130 $fields_layout = strtolower( $fields_layout );
131
132 if ( ! in_array( $fields_layout, array( 'column', 'row' ), true ) ) {
133 return;
134 }
135
136 $this->fields_layout = $fields_layout;
137 }
138
139 /**
140 * @param mixed $load_nonce
141 */
142 public function set_load_nonce( $load_nonce ) {
143 $load_nonce = strtolower( $load_nonce );
144
145 if ( ! in_array( $load_nonce, array( 'render', 'hide' ), true ) ) {
146 return;
147 }
148
149 $this->load_nonce = $load_nonce;
150 }
151
152 /**
153 * @param mixed $required_mark
154 */
155 public function set_required_mark( $required_mark ) {
156 $this->required_mark = $required_mark;
157 }
158
159 /**
160 * @param mixed $submit_type
161 */
162 public function set_submit_type( $submit_type ) {
163 $submit_type = strtolower( $submit_type );
164
165 if ( ! in_array( $submit_type, array( 'reload', 'ajax' ), true ) ) {
166 return;
167 }
168
169 $this->submit_type = $submit_type;
170 }
171
172 public function to_array(): array {
173 return array(
174 'form_id' => $this->form_id,
175 'submit_type' => $this->submit_type,
176 'required_mark' => $this->required_mark,
177 'fields_layout' => $this->fields_layout,
178 'enable_progress' => $this->enable_progress,
179 'fields_label_tag' => $this->fields_label_tag,
180 'load_nonce' => $this->load_nonce,
181 'use_csrf' => $this->use_csrf,
182 );
183 }
184
185 public function set_from_array( array $attributes ) {
186 foreach ( $attributes as $attr => $value ) {
187 if ( ! array_key_exists( $attr, $this->props ) ) {
188 continue;
189 }
190 $setter = array( $this, self::SETTER_PREFIX . $attr );
191
192 if ( is_callable( $setter ) ) {
193 call_user_func( $setter, $value );
194
195 continue;
196 }
197
198 $this->props[ $attr ] = $value;
199 }
200 }
201
202 /**
203 * @param $property
204 * @param false $default
205 *
206 * @return mixed
207 */
208 public function argument( $property, $default = '' ) {
209 if ( ! array_key_exists( $property, $this->props ) ) {
210 return $default;
211 }
212 $value = $this->props[ $property ];
213
214 return ( is_null( $value ) || '' === $value ) ? $default : $value;
215 }
216
217 public function is_use_nonce(): bool {
218 return 'render' === $this->load_nonce;
219 }
220
221 public function is_use_csrf() {
222 return $this->use_csrf;
223 }
224
225 public static function arguments(): array {
226 return ( new static() )->to_array();
227 }
228
229 public static function get_options( $for_elementor = false ): array {
230 $submit_type = array(
231 '' => __( 'Default', 'jet-form-builder' ),
232 'reload' => __( 'Page Reload', 'jet-form-builder' ),
233 'ajax' => __( 'AJAX', 'jet-form-builder' ),
234 );
235 $fields_layout = array(
236 '' => __( 'Default', 'jet-form-builder' ),
237 'column' => __( 'Column', 'jet-form-builder' ),
238 'row' => __( 'Row', 'jet-form-builder' ),
239 );
240
241 $label_tag = array(
242 '' => 'Default',
243 'div' => __( 'DIV', 'jet-form-builder' ),
244 'label' => __( 'LABEL', 'jet-form-builder' ),
245 );
246
247 $load_nonce = array(
248 'hide' => __( 'Disable', 'jet-form-builder' ),
249 'render' => __( 'WordPress Nonce', 'jet-form-builder' ),
250 'csrf' => __( 'JetFormBuilder Token', 'jet-form-builder' ),
251 );
252
253 if ( ! $for_elementor ) {
254 $submit_type = Tools::prepare_list_for_js( $submit_type );
255 $fields_layout = Tools::prepare_list_for_js( $fields_layout );
256 $label_tag = Tools::prepare_list_for_js( $label_tag );
257 $load_nonce = Tools::prepare_list_for_js( $load_nonce );
258 }
259
260 return array(
261 'submit_type' => $submit_type,
262 'fields_layout' => $fields_layout,
263 'fields_label_tag' => $label_tag,
264 'load_nonce' => $load_nonce,
265 );
266 }
267
268 /**
269 * @return string
270 */
271 public function get_submit_type(): string {
272 return $this->submit_type ?: 'reload';
273 }
274
275 public function __get( $name ) {
276 if ( ! array_key_exists( $name, $this->props ) ) {
277 return null;
278 }
279
280 return $this->props[ $name ];
281 }
282
283 public function __set( $name, $value ) {
284 if ( ! array_key_exists( $name, $this->props ) ) {
285 return;
286 }
287
288 $this->props[ $name ] = $value;
289 }
290
291 }
292