PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.05.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.05.02
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / controllers / FrmSimpleBlocksController.php

FrmSimpleBlocksController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 4.05.02, at classes/controllers/FrmSimpleBlocksController.php

142 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class FrmSimpleBlocksController {
4
5 /**
6 * Enqueue Formidable Simple Blocks' js and CSS for editor in admin.
7 */
8 public static function block_editor_assets() {
9 $version = FrmAppHelper::plugin_version();
10
11 wp_register_script(
12 'formidable-form-selector',
13 FrmAppHelper::plugin_url() . '/js/formidable_blocks.js',
14 array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-editor' ),
15 $version,
16 true
17 );
18
19 $icon = str_replace( 'dashicons-', '', apply_filters( 'frm_icon', 'svg' ) );
20 $block_name = FrmAppHelper::get_menu_name();
21 if ( $block_name === 'Formidable' ) {
22 $block_name = 'Formidable Forms';
23 }
24
25 $script_vars = array(
26 'forms' => self::get_forms_options(),
27 'icon' => $icon,
28 'name' => $block_name,
29 'link' => FrmAppHelper::admin_upgrade_link( 'block' ),
30 );
31
32 wp_localize_script( 'formidable-form-selector', 'formidable_form_selector', $script_vars );
33 if ( function_exists( 'wp_set_script_translations' ) ) {
34 wp_set_script_translations( 'formidable-form-selector', 'formidable' );
35 }
36
37 wp_enqueue_style(
38 'formidable_block-editor-css',
39 FrmAppHelper::plugin_url() . '/css/frm_blocks.css',
40 array( 'wp-edit-blocks' ),
41 $version
42 );
43 }
44
45 /**
46 * Returns a filtered list of form options with the name as label and the id as value, sorted by label
47 *
48 * @return array
49 */
50 private static function get_forms_options() {
51 $forms = FrmForm::getAll(
52 array(
53 'is_template' => 0,
54 'status' => 'published',
55 array(
56 'or' => 1,
57 'parent_form_id' => null,
58 'parent_form_id <' => 1,
59 ),
60 ),
61 'name'
62 );
63
64 return array_map( 'FrmSimpleBlocksController::set_form_options', $forms );
65 }
66
67 /**
68 * Returns an array for a form with name as label and id as value
69 *
70 * @param $form
71 *
72 * @return array
73 */
74 private static function set_form_options( $form ) {
75 return array(
76 'label' => $form->name,
77 'value' => $form->id,
78 );
79 }
80
81 /**
82 * Registers simple form block
83 */
84 public static function register_simple_form_block() {
85 if ( ! is_callable( 'register_block_type' ) ) {
86 return;
87 }
88
89 if ( is_admin() ) {
90 FrmStylesController::enqueue_css( 'register', true );
91 }
92
93 register_block_type(
94 'formidable/simple-form',
95 array(
96 'attributes' => array(
97 'formId' => array(
98 'type' => 'string',
99 ),
100 'title' => array(
101 'type' => 'string',
102 ),
103 'description' => array(
104 'type' => 'string',
105 ),
106 'minimize' => array(
107 'type' => 'string',
108 ),
109 'className' => array(
110 'type' => 'string',
111 ),
112 ),
113 'editor_style' => 'formidable',
114 'editor_script' => 'formidable-form-selector',
115 'render_callback' => 'FrmSimpleBlocksController::simple_form_render',
116
117 )
118 );
119 }
120
121 /**
122 * Renders a form given the specified attributes.
123 *
124 * @param $attributes
125 *
126 * @return string
127 */
128 public static function simple_form_render( $attributes ) {
129 if ( ! isset( $attributes['formId'] ) ) {
130 return '';
131 }
132
133 $params = array_filter( $attributes );
134 $params['id'] = $params['formId'];
135 unset( $params['formId'] );
136
137 $form = FrmFormsController::get_form_shortcode( $params );
138
139 return str_replace( ' frm_logic_form ', ' ', $form ); // prevent the form from hiding
140 }
141 }
142