PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.5.4
JetFormBuilder — Dynamic Blocks Form Builder v1.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 / includes / admin / editor.php
jetformbuilder / includes / admin Last commit date
pages 4 years ago tabs-handlers 4 years ago editor.php 4 years ago
editor.php
429 lines
1 <?php
2
3 namespace Jet_Form_Builder\Admin;
4
5 use Jet_Form_Builder\Admin\Tabs_Handlers\Tab_Handler_Manager;
6 use Jet_Form_Builder\Classes\Condition_Helper;
7 use Jet_Form_Builder\Classes\Tools;
8 use Jet_Form_Builder\Gateways\Gateway_Manager;
9 use Jet_Form_Builder\Plugin;
10
11 /**
12 * Form editor class
13 * Thanks Tom J Nowell for initial editor idea and inspiration!
14 */
15
16 // If this file is called directly, abort.
17 if ( ! defined( 'WPINC' ) ) {
18 die;
19 }
20
21 /**
22 * Define Editor class
23 */
24 class Editor {
25
26 const EDITOR_HANDLE = 'jet-form-builder-editor';
27 const EDITOR_PACKAGE_HANDLE = 'jet-form-builder-editor-package';
28
29 public function __construct() {
30 add_action( 'enqueue_block_editor_assets', array( $this, 'admin_assets' ) );
31 }
32
33 /**
34 * Register admin assets
35 *
36 * @return void [type] [description]
37 */
38 public function admin_assets() {
39 if ( jet_form_builder()->post_type->is_form_editor ) {
40 $this->enqueue_assets();
41 } else {
42 $this->enqueue_form_assets();
43 }
44 }
45
46 /**
47 * Returns taxonomies list for the config
48 *
49 * @return [type] [description]
50 */
51 public function get_taxonomies_list() {
52
53 $taxonomies = get_taxonomies( array(), 'objects' );
54
55 $result = array();
56
57 foreach ( $taxonomies as $tax ) {
58 $result[] = array(
59 'value' => $tax->name,
60 'label' => sprintf( '%1$s (%2$s)', $tax->label, $tax->name ),
61 );
62 }
63
64 return $result;
65
66 }
67
68 public function get_preset_config() {
69 return apply_filters(
70 'jet-form-builder/editor/preset-config',
71 array(
72 'global_fields' => array(
73 array(
74 'name' => 'from',
75 'label' => __( 'Source:', 'jet-form-builder' ),
76 'type' => 'select',
77 'options' => Tools::with_placeholder(
78 array(
79 array(
80 'value' => 'post',
81 'label' => __( 'Post', 'jet-form-builder' ),
82 ),
83 array(
84 'value' => 'user',
85 'label' => __( 'User', 'jet-form-builder' ),
86 ),
87 array(
88 'value' => 'query_var',
89 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
90 ),
91 )
92 ),
93 ),
94 array(
95 'name' => 'post_from',
96 'label' => __( 'Get post ID from:', 'jet-form-builder' ),
97 'type' => 'select',
98 'options' => Tools::with_placeholder(
99 array(
100 array(
101 'value' => 'current_post',
102 'label' => __( 'Current post', 'jet-form-builder' ),
103 ),
104 array(
105 'value' => 'query_var',
106 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
107 ),
108 )
109 ),
110 'condition' => array(
111 'field' => 'from',
112 'value' => 'post',
113 ),
114 ),
115 array(
116 'name' => 'user_from',
117 'label' => __( 'Get user ID from:', 'jet-form-builder' ),
118 'type' => 'select',
119 'options' => Tools::with_placeholder(
120 array(
121 array(
122 'value' => 'current_user',
123 'label' => __( 'Current user', 'jet-form-builder' ),
124 ),
125 array(
126 'value' => 'query_var',
127 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
128 ),
129 )
130 ),
131 'condition' => array(
132 'field' => 'from',
133 'value' => 'user',
134 ),
135 ),
136 array(
137 'name' => 'query_var',
138 'label' => __( 'Query variable name:', 'jet-form-builder' ),
139 'type' => 'text',
140 'custom_condition' => 'query_var',
141 'position' => 'dynamic',
142 ),
143 ),
144 'map_fields' => array(
145 array(
146 'name' => 'key',
147 'label' => __( 'Query variable key', 'jet-form-builder' ),
148 'type' => 'text',
149 'position' => 'general',
150 'parent_condition' => array(
151 'field' => 'from',
152 'value' => 'query_var',
153 ),
154 ),
155 array(
156 'name' => 'prop',
157 'label' => __( 'Post property', 'jet-form-builder' ),
158 'type' => 'select',
159 'options' => Tools::with_placeholder(
160 array(
161 array(
162 'value' => 'ID',
163 'label' => __( 'Post ID', 'jet-form-builder' ),
164 ),
165 array(
166 'value' => 'post_title',
167 'label' => __( 'Post Title', 'jet-form-builder' ),
168 ),
169 array(
170 'value' => 'post_content',
171 'label' => __( 'Post Content', 'jet-form-builder' ),
172 ),
173 array(
174 'value' => 'post_status',
175 'label' => __( 'Post Status', 'jet-form-builder' ),
176 ),
177 array(
178 'value' => 'post_author',
179 'label' => __( 'Post Author', 'jet-form-builder' ),
180 ),
181 array(
182 'value' => 'post_excerpt',
183 'label' => __( 'Post Excerpt', 'jet-form-builder' ),
184 ),
185 array(
186 'value' => 'post_date',
187 'label' => __( 'Post Date', 'jet-form-builder' ),
188 ),
189 array(
190 'value' => 'post_date_gmt',
191 'label' => __( 'Post Date GMT', 'jet-form-builder' ),
192 ),
193 array(
194 'value' => 'post_thumb',
195 'label' => __( 'Post Thumbnail', 'jet-form-builder' ),
196 ),
197 array(
198 'value' => 'post_meta',
199 'label' => __( 'Post Meta', 'jet-form-builder' ),
200 ),
201 array(
202 'value' => 'post_terms',
203 'label' => __( 'Post Terms', 'jet-form-builder' ),
204 ),
205 )
206 ),
207 'parent_condition' => array(
208 'field' => 'from',
209 'value' => 'post',
210 ),
211 ),
212 array(
213 'name' => 'key',
214 'label' => __( 'Taxonomy', 'jet-form-builder' ),
215 'type' => 'select',
216 'options' => Tools::with_placeholder( $this->get_taxonomies_list() ),
217 'parent_condition' => array(
218 'field' => 'from',
219 'value' => 'post',
220 ),
221 'condition' => array(
222 'field' => 'prop',
223 'value' => 'post_terms',
224 ),
225 ),
226 array(
227 'name' => 'key',
228 'label' => __( 'Meta field key', 'jet-form-builder' ),
229 'type' => 'text',
230 'parent_condition' => array(
231 'field' => 'from',
232 'value' => 'post',
233 ),
234 'condition' => array(
235 'field' => 'prop',
236 'value' => 'post_meta',
237 ),
238 ),
239 array(
240 'name' => 'prop',
241 'label' => __( 'User field', 'jet-form-builder' ),
242 'type' => 'select',
243 'options' => Tools::with_placeholder(
244 array(
245 array(
246 'value' => 'ID',
247 'label' => __( 'User ID', 'jet-form-builder' ),
248 ),
249 array(
250 'value' => 'user_login',
251 'label' => __( 'User Login', 'jet-form-builder' ),
252 ),
253 array(
254 'value' => 'user_email',
255 'label' => __( 'Email', 'jet-form-builder' ),
256 ),
257 array(
258 'value' => 'password',
259 'label' => __( 'Password', 'jet-form-builder' ),
260 ),
261 array(
262 'value' => 'first_name',
263 'label' => __( 'First Name', 'jet-form-builder' ),
264 ),
265 array(
266 'value' => 'last_name',
267 'label' => __( 'Last Name', 'jet-form-builder' ),
268 ),
269 array(
270 'value' => 'user_url',
271 'label' => __( 'User URL', 'jet-form-builder' ),
272 ),
273 array(
274 'value' => 'user_meta',
275 'label' => __( 'User Meta', 'jet-form-builder' ),
276 ),
277 )
278 ),
279 'parent_condition' => array(
280 'field' => 'from',
281 'value' => 'user',
282 ),
283 ),
284 array(
285 'name' => 'key',
286 'label' => __( 'Meta field key', 'jet-form-builder' ),
287 'type' => 'text',
288 'parent_condition' => array(
289 'field' => 'from',
290 'value' => 'user',
291 ),
292 'condition' => array(
293 'field' => 'prop',
294 'value' => 'user_meta',
295 ),
296 ),
297 ),
298 )
299 );
300 }
301
302 public function get_messages_default() {
303 return Plugin::instance()->post_type->get_messages_default();
304 }
305
306 /**
307 * Enqueue editor assets
308 *
309 * @return void
310 */
311 public function enqueue_assets() {
312 do_action( 'jet-form-builder/editor-package/before', $this, self::EDITOR_PACKAGE_HANDLE );
313
314 wp_enqueue_script(
315 self::EDITOR_PACKAGE_HANDLE,
316 JET_FORM_BUILDER_URL . 'assets/js/package.js',
317 array(
318 'wp-editor',
319 'wp-core-data',
320 'wp-data',
321 'wp-block-library',
322 'wp-format-library',
323 'wp-api-fetch',
324 ),
325 JET_FORM_BUILDER_VERSION,
326 true
327 );
328
329 wp_set_script_translations(
330 self::EDITOR_PACKAGE_HANDLE,
331 'jet-form-builder',
332 Plugin::instance()->plugin_dir( 'languages' )
333 );
334
335 do_action( 'jet-form-builder/editor-assets/before', $this, self::EDITOR_HANDLE );
336
337 wp_enqueue_script(
338 self::EDITOR_HANDLE,
339 JET_FORM_BUILDER_URL . 'assets/js/editor.js',
340 array(),
341 JET_FORM_BUILDER_VERSION,
342 true
343 );
344
345 wp_enqueue_style(
346 self::EDITOR_HANDLE,
347 JET_FORM_BUILDER_URL . 'assets/css/editor.css',
348 array(
349 'media',
350 'l10n',
351 'buttons',
352 'wp-edit-blocks',
353 'wp-editor',
354 ),
355 JET_FORM_BUILDER_VERSION,
356 'all'
357 );
358
359 $conditions_settings = jet_form_builder()->form_handler->action_handler->condition_manager()->get_settings();
360
361 wp_localize_script(
362 self::EDITOR_PACKAGE_HANDLE,
363 'JetFormEditorData',
364 array(
365 'presetConfig' => $this->get_preset_config(),
366 'messagesDefault' => $this->get_messages_default(),
367 'gateways' => Gateway_Manager::instance()->editor_data(),
368 'helpForRepeaters' => $this->get_help_for_repeaters(),
369 'global_settings' => Tab_Handler_Manager::instance()->all(),
370 'jetEngineVersion' => Tools::get_jet_engine_version(),
371 'actionConditionSettings' => $conditions_settings,
372 'argumentsSource' => Tools::get_form_settings_options()
373 )
374 );
375
376 do_action( 'jet-form-builder/editor-assets/after', $this, self::EDITOR_HANDLE );
377 }
378
379 private function get_help_for_repeaters() {
380 return array(
381 'conditional_block' => array(
382 'label' => __( 'With many conditions for the block, they are checked with the AND operator', 'jet-form-builder' ),
383 ),
384 'conditional_block_or' => array(
385 'label' => __( 'With many conditions for the block, they are checked with the OR operator', 'jet-form-builder' ),
386 ),
387 'conditional_action' => array(
388 'label' => __( 'With many conditions for the action, they are checked with the AND operator', 'jet-form-builder' ),
389 ),
390 'conditional_action_or' => array(
391 'label' => __( 'With many conditions for the action, they are checked with the OR operator', 'jet-form-builder' ),
392 ),
393 );
394 }
395
396 public function enqueue_form_assets() {
397
398 $handle = 'jet-form-builder/form';
399
400 do_action( 'jet-form-builder/other-editor-assets/before', $this, $handle );
401
402 wp_register_script(
403 $handle,
404 JET_FORM_BUILDER_URL . 'assets/js/form-block.js',
405 array(
406 'wp-editor',
407 'wp-core-data',
408 'wp-data',
409 'wp-block-library',
410 'wp-format-library',
411 'wp-api-fetch',
412 ),
413 JET_FORM_BUILDER_VERSION,
414 true
415 );
416
417 wp_register_style(
418 'jet-form-builder-others',
419 Plugin::instance()->plugin_url( 'assets/css/frontend.css' ),
420 array(),
421 Plugin::instance()->get_version()
422 );
423
424 do_action( 'jet-form-builder/other-editor-assets/after', $this, $handle );
425
426 }
427
428 }
429