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