PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.1
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / includes / blocks / form-builder / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.1, at includes/blocks/form-builder/block.php

418 lines 14.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ABlocks\Blocks\FormBuilder;
4
5 use ABlocks\Classes\BlockBaseAbstract;
6 use ABlocks\Classes\CssGenerator;
7 use ABlocks\Controls\Alignment;
8 use ABlocks\Controls\Typography;
9 use ABlocks\Controls\Dimensions;
10 use ABlocks\Controls\Border;
11 use ABlocks\Controls\Range;
12
13 class Block extends BlockBaseAbstract {
14
15 protected $block_name = 'form-builder';
16
17 public function __construct() {
18 parent::__construct();
19 add_filter( 'ablocks/get_render_block_content', [ $this, 'render_static_block_content' ], 10, 3 );
20 }
21
22 public function render_static_block_content( $content, $attributes, $block_instance ) {
23 if ( $block_instance->name === $this->namespace . '/' . $this->block_name ) {
24 if ( is_user_logged_in() &&
25 in_array( $attributes['formType'], array( 'login', 'registration', 'forget_password' ), true )
26 ) {
27 return '';
28 }
29 return $content;
30 }
31 return $content;
32 }
33
34 public function build_css( $attributes ) {
35 $css_generator = new CssGenerator( $attributes, $this->block_name );
36
37 $css_generator->add_class_styles(
38 '{{WRAPPER}} .ablocks-form-builder__field',
39 $this->get_field_css( $attributes ),
40 $this->get_field_css( $attributes, 'Tablet' ),
41 $this->get_field_css( $attributes, 'Mobile' ),
42 );
43
44 $css_generator->add_class_styles(
45 '{{WRAPPER}} .ablocks-form-builder__label',
46 $this->get_label_css( $attributes ),
47 $this->get_label_css( $attributes, 'Tablet' ),
48 $this->get_label_css( $attributes, 'Mobile' ),
49 );
50 $css_generator->add_class_styles(
51 '{{WRAPPER}} .ablocks-form-builder__helper-text',
52 $this->get_helper_text_css( $attributes ),
53 $this->get_helper_text_css( $attributes, 'Tablet' ),
54 $this->get_helper_text_css( $attributes, 'Mobile' ),
55 );
56
57 $css_generator->add_class_styles(
58 '{{WRAPPER}} .ablocks-form-builder__input',
59 $this->get_input_css( $attributes ),
60 $this->get_input_css( $attributes, 'Tablet' ),
61 $this->get_input_css( $attributes, 'Mobile' ),
62 );
63 $css_generator->add_class_styles(
64 '{{WRAPPER}} .ablocks-form-builder__input:hover',
65 $this->get_input_hover_css( $attributes ),
66 $this->get_input_hover_css( $attributes, 'Tablet' ),
67 $this->get_input_hover_css( $attributes, 'Mobile' ),
68 );
69 $css_generator->add_class_styles(
70 '{{WRAPPER}} .ablocks-form-builder__input:focus',
71 $this->get_input_focus_css( $attributes ),
72 $this->get_input_focus_css( $attributes, 'Tablet' ),
73 $this->get_input_focus_css( $attributes, 'Mobile' ),
74 );
75
76 $css_generator->add_class_styles(
77 '{{WRAPPER}} .ablocks-form-builder__input::placeholder',
78 $this->get_input_placeholder_css( $attributes ),
79 $this->get_input_placeholder_css( $attributes, 'Tablet' ),
80 $this->get_input_placeholder_css( $attributes, 'Mobile' ),
81 );
82 $css_generator->add_class_styles(
83 '{{WRAPPER}} .ablocks-form-builder__input-icon,{{WRAPPER}} .ablocks-form-builder__input-toggle-password',
84 $this->get_input_position_css( $attributes ),
85 $this->get_input_position_css( $attributes, 'Tablet' ),
86 $this->get_input_position_css( $attributes, 'Mobile' ),
87 );
88
89 $css_generator->add_class_styles(
90 '{{WRAPPER}} .ablocks-form-builder__submit-button',
91 $this->get_alignment_button_css( $attributes ),
92 $this->get_alignment_button_css( $attributes, 'Tablet' ),
93 $this->get_alignment_button_css( $attributes, 'Mobile' ),
94 );
95
96 $css_generator->add_class_styles(
97 '{{WRAPPER}} .ablocks-form-builder__submit-button',
98 $this->get_submit_button_css( $attributes ),
99 $this->get_submit_button_css( $attributes, 'Tablet' ),
100 $this->get_submit_button_css( $attributes, 'Mobile' ),
101 );
102
103 $css_generator->add_class_styles(
104 '{{WRAPPER}} .ablocks-form-builder__submit-button:hover',
105 $this->get_submit_button_hover_css( $attributes ),
106 $this->get_submit_button_hover_css( $attributes, 'Tablet' ),
107 $this->get_submit_button_hover_css( $attributes, 'Mobile' ),
108 );
109 $css_generator->add_class_styles(
110 '{{WRAPPER}} .ablocks-block--form-builder__navigator',
111 $this->get_navigator_css( $attributes ),
112 $this->get_navigator_css( $attributes, 'Tablet' ),
113 $this->get_navigator_css( $attributes, 'Mobile' ),
114 );
115 $css_generator->add_class_styles(
116 '{{WRAPPER}} .ablocks-block--form-builder__navigator-redirect-page',
117 $this->get_navigator_spacing_css( $attributes ),
118 $this->get_navigator_spacing_css( $attributes, 'Tablet' ),
119 $this->get_navigator_spacing_css( $attributes, 'Mobile' ),
120 );
121 $css_generator->add_class_styles(
122 '{{WRAPPER}} .ablocks-block--form-builder__success',
123 $this->get_succsss_styles_css( $attributes ),
124 $this->get_succsss_styles_css( $attributes, 'Tablet' ),
125 $this->get_succsss_styles_css( $attributes, 'Mobile' ),
126 );
127 $css_generator->add_class_styles(
128 '{{WRAPPER}} .ablocks-block--form-builder__error',
129 $this->get_error_styles_css( $attributes ),
130 $this->get_error_styles_css( $attributes, 'Tablet' ),
131 $this->get_error_styles_css( $attributes, 'Mobile' ),
132 );
133 $css_generator->add_class_styles(
134 '{{WRAPPER}} .ablocks-block--form-builder__feedback-message',
135 $this->get_success_error_common_styles_css( $attributes ),
136 $this->get_success_error_common_styles_css( $attributes, 'Tablet' ),
137 $this->get_success_error_common_styles_css( $attributes, 'Mobile' ),
138 );
139 return $css_generator->generate_css();
140 }
141
142 public function get_field_css( $attributes, $device = '' ) {
143 $field_css = array_merge(
144 Range::get_css([
145 'attributeValue' => $attributes['rowsSpacing'],
146 'attributeObjectKey' => 'value',
147 'isResponsive' => true,
148 'defaultValue' => 0,
149 'unitDefaultValue' => 'px',
150 'property' => 'margin-top',
151 'device' => $device,
152 ]),
153 Range::get_css([
154 'attributeValue' => $attributes['rowsSpacing'],
155 'attributeObjectKey' => 'value',
156 'isResponsive' => true,
157 'defaultValue' => 0,
158 'unitDefaultValue' => 'px',
159 'property' => 'margin-bottom',
160 'device' => $device,
161 ]),
162 );
163 return $field_css;
164 }
165
166 public function get_label_css( $attributes, $device = '' ) {
167 $label_css = array_merge(
168 Typography::get_css( $attributes['labelTypography'], '', $device ),
169 Alignment::get_css( $attributes['labelAlignment'], 'text-align', $device ),
170 Range::get_css([
171 'attributeValue' => $attributes['labelSpacing'],
172 'attributeObjectKey' => 'value',
173 'isResponsive' => true,
174 'defaultValue' => 10,
175 'unitDefaultValue' => 'px',
176 'property' => 'margin-bottom',
177 'device' => $device,
178 ]),
179 );
180 if ( ! empty( $label_css['margin-bottom'] ) ) {
181 $label_css['margin-bottom'] = $label_css['margin-bottom'] . ' !important';
182 }
183
184 if ( ! empty( $attributes['labelColor'] ) ) {
185 $label_css['color'] = $attributes['labelColor'];
186 }
187
188 if ( ! $attributes['showLabels'] ) {
189 $label_css['display'] = 'none';
190 }
191
192 return $label_css;
193 }
194 public function get_helper_text_css( $attributes, $device = '' ) {
195 $helper_text_css = array_merge(
196 Typography::get_css( $attributes['helperTextTypography'], '', $device ),
197 Alignment::get_css( $attributes['labelAlignment'], 'text-align', $device ),
198 Range::get_css([
199 'attributeValue' => $attributes['helperTextSpacing'],
200 'attributeObjectKey' => 'value',
201 'isResponsive' => true,
202 'defaultValue' => 10,
203 'unitDefaultValue' => 'px',
204 'property' => 'margin-bottom',
205 'device' => $device,
206 ]),
207 );
208
209 if ( ! $attributes['showLabels'] ) {
210 $helper_text_css['display'] = 'none';
211 }
212
213 if ( ! empty( $attributes['helperTextSpacing'][ 'value' . $device ] ) ) {
214 $helper_text_css['margin-top'] = $attributes['helperTextSpacing'][ 'value' . $device ] . 'px';
215 $helper_text_css['margin-bottom'] = $attributes['helperTextSpacing'][ 'value' . $device ] . 'px';
216 }
217 if ( ! empty( $attributes['helperTextColor'] ) ) {
218 $helper_text_css['color'] = $attributes['helperTextColor'];
219 }
220
221 return $helper_text_css;
222 }
223
224 public function get_input_css( $attributes, $device = '' ) {
225 // Initialize the $css array before using it
226 $css = array();
227
228 // Check if the inputBorder's borderStyle is 'default' and apply default border styles
229 if ( isset( $attributes['inputBorder']['borderStyle'] ) && $attributes['inputBorder']['borderStyle'] === 'default' ) {
230 $css['border'] = '1px solid #A7AAAD';
231 $css['border-radius'] = '5px';
232 }
233
234 // Merge the base CSS with typography, border, and padding CSS
235 $input_css = array_merge(
236 $css, // Include the default border styles if set
237 Alignment::get_css( $attributes['inputAlignment'], 'text-align', $device ),
238 Typography::get_css( $attributes['inputTypography'], '', $device ),
239 Border::get_css( $attributes['inputBorder'], '', $device ),
240 Dimensions::get_css( $attributes['inputPadding'], 'padding', $device )
241 );
242
243 // Add input text color if it's set in the attributes
244 if ( ! empty( $attributes['inputColor'] ) ) {
245 $input_css['color'] = $attributes['inputColor'] . '!important';
246 }
247
248 // Add background color if it's set in the attributes
249 if ( ! empty( $attributes['inputBgColor'] ) ) {
250 $input_css['background-color'] = $attributes['inputBgColor'];
251 }
252
253 // Ensure box-sizing is set to 'border-box'
254 $input_css['box-sizing'] = 'border-box';
255
256 return $input_css;
257 }
258
259 public function get_input_hover_css( $attributes, $device = '' ) {
260 $css = array();
261
262 // Check if the inputBorder's borderStyle is 'default' and apply default border styles
263 if ( isset( $attributes['inputBorder']['borderStyle'] ) && $attributes['inputBorder']['borderStyle'] === 'default' ) {
264 $css['border'] = '1px solid #A7AAAD';
265 $css['border-radius'] = '5px';
266 }
267 // Get the border hover CSS based on inputBorder attribute
268 $input_focus_css = array_merge(
269 $css,
270 Border::get_hover_css( $attributes['inputBorder'], '', $device )
271 );
272
273 return $input_focus_css;
274 }
275 public function get_input_focus_css( $attributes, $device = '' ) {
276 $css = array();
277
278 // Check if the inputBorder's borderStyle is 'default' and apply default border styles
279 if ( isset( $attributes['inputBorder']['borderStyle'] ) && $attributes['inputBorder']['borderStyle'] === 'default' ) {
280 $css['border'] = '1px solid #A7AAAD';
281 $css['border-radius'] = '5px';
282 }
283 // Get the border hover CSS based on inputBorder attribute
284 $input_focus_css = array_merge(
285 $css,
286 Border::get_hover_css( $attributes['inputBorder'], '', $device )
287 );
288
289 return $input_focus_css;
290 }
291 public function get_input_placeholder_css( $attributes, $device = '' ) {
292 // Initialize placeholder CSS array
293 $placeholder_css = array_merge(
294 // Apply typography for the placeholder (font size, font family, etc.)
295 Typography::get_css( $attributes['inputTypography'], '', $device ),
296 // Apply alignment if specified
297 Alignment::get_css( $attributes['inputAlignment'], 'text-align', $device )
298 );
299 // Check if placeholder color is defined, and apply it
300 if ( ! empty( $attributes['inputPlaceholderColor'] ) ) {
301 $placeholder_css['color'] = $attributes['inputPlaceholderColor'] . '!important'; // Add !important to override conflicting styles
302 }
303 return $placeholder_css;
304
305 }
306 public function get_input_position_css( $attributes, $device = '' ) {
307 // Access the inputIconPosition attribute from the attributes array
308 $css = array_merge(
309 Range::get_css([
310 'attributeValue' => $attributes['inputIconPosition'],
311 'isResponsive' => false,
312 'defaultValue' => 60,
313 'unitDefaultValue' => '%',
314 'property' => 'top',
315 'device' => $device,
316 ]),
317 );
318 return $css;
319 }
320 public function get_alignment_button_css( $attributes, $device = '' ) {
321 $button_alignment_css = array_merge(
322 Alignment::get_css( $attributes['buttonTextAlignment'], 'text-align', $device ),
323 Alignment::get_css( $attributes['buttonAlignment'], 'align-self', $device )
324 );
325
326 return $button_alignment_css;
327 }
328
329
330 public function get_submit_button_css( $attributes, $device = '' ) {
331 $button_css = array_merge(
332 Border::get_css( $attributes['buttonBorder'], '', $device ),
333 Typography::get_css( $attributes['buttonTypography'], '', $device ),
334 Dimensions::get_css( $attributes['buttonPadding'], 'padding', $device ),
335 );
336 if ( ! empty( $attributes['buttonColor'] ) ) {
337 $button_css['color'] = $attributes['buttonColor'];
338 }
339
340 if ( ! empty( $attributes['buttonBgColor'] ) ) {
341 $button_css['background-color'] = $attributes['buttonBgColor'];
342 }
343
344 return $button_css;
345 }
346
347 public function get_submit_button_hover_css( $attributes, $device = '' ) {
348 $button_hover_css = Border::get_hover_css( $attributes['buttonBorder'], '', $device );
349
350 if ( ! empty( $attributes['buttonHColor'] ) ) {
351 $button_hover_css['color'] = $attributes['buttonHColor'];
352 }
353
354 if ( ! empty( $attributes['buttonBgHColor'] ) ) {
355 $button_hover_css['background-color'] = $attributes['buttonBgHColor'];
356 }
357
358 return $button_hover_css;
359 }
360 public function get_navigator_css( $attributes, $device = '' ) {
361 $css = [];
362 if ( ! empty( $attributes['navigatorColor'] ) ) {
363 $css['color'] = $attributes['navigatorColor'];
364 }
365 return array_merge(
366 Typography::get_css( $attributes['navigatorTypography'], '', $device ),
367 Dimensions::get_css( $attributes['navigatorPadding'], 'padding', $device ),
368 Alignment::get_css( $attributes['navigatorAlignment'], 'text-align', $device ),
369 $css
370 );
371 }
372 public function get_navigator_spacing_css( $attributes, $device = '' ) {
373 // Access the inputIconPosition attribute from the attributes array
374 $css = array_merge(
375 Range::get_css([
376 'attributeValue' => $attributes['navigatorSpacing'],
377 'isResponsive' => false,
378 'defaultValue' => 10,
379 'unitDefaultValue' => 'px',
380 'property' => 'margin-bottom',
381 'device' => $device,
382 ]),
383 );
384 return $css;
385
386 }
387 public function get_succsss_styles_css( $attributes, $device = '' ) {
388 $css = [];
389 if ( ! empty( $attributes['successBackground'] ) ) {
390 $css['background'] = $attributes['successBackground'];
391 }
392 if ( ! empty( $attributes['successColor'] ) ) {
393 $css['color'] = $attributes['successColor'];
394 }
395 return $css;
396 }
397 public function get_error_styles_css( $attributes, $device = '' ) {
398 $css = [];
399 if ( ! empty( $attributes['errorBackground'] ) ) {
400 $css['background'] = $attributes['errorBackground'];
401 }
402 if ( ! empty( $attributes['errorColor'] ) ) {
403 $css['color'] = $attributes['errorColor'];
404 }
405 return $css;
406 }
407 public function get_success_error_common_styles_css( $attributes, $device = '' ) {
408 $css = [];
409 return array_merge(
410 Typography::get_css( $attributes['successErrorTypography'], '', $device ),
411 Alignment::get_css( $attributes['successErrorAlignment'], 'text-align', $device ),
412 Dimensions::get_css( $attributes['successErrorPadding'], 'padding', $device ),
413 $css,
414 );
415 }
416
417 }
418