PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.11.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.11.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-radio / block.php

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

73 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\FormRadio;
3
4 use ABlocks\Controls\Range;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 use ABlocks\Classes\BlockBaseAbstract;
11 use ABlocks\Classes\CssGenerator;
12
13 class Block extends BlockBaseAbstract {
14 protected $parent_block_name = 'form-builder';
15 protected $block_name = 'form-radio';
16
17 public function build_css( $attributes ) {
18 $css_generator = new CssGenerator( $attributes );
19 $css_generator->add_class_styles(
20 '{{WRAPPER}}',
21 $this->get_wrapper_css( $attributes ),
22 $this->get_wrapper_css( $attributes, 'Tablet' ),
23 $this->get_wrapper_css( $attributes, 'Mobile' )
24 );
25 $css_generator->add_class_styles(
26 '{{WRAPPER}}.ablocks-block--form-radio',
27 $this->get_input_block_main_wrapper( $attributes ),
28 $this->get_input_block_main_wrapper( $attributes, 'Tablet' ),
29 $this->get_input_block_main_wrapper( $attributes, 'Mobile' ),
30 );
31 $css_generator->add_class_styles(
32 '{{WRAPPER}} .ablocks-form-builder__radio-option',
33 $this->get_radio_dynamic_width_css( $attributes ),
34 $this->get_radio_dynamic_width_css( $attributes, 'Tablet' ),
35 $this->get_radio_dynamic_width_css( $attributes, 'Mobile' )
36 );
37 return $css_generator->generate_css();
38 }
39 public function get_radio_dynamic_width_css( $attributes, $device = '' ) {
40 $css = [];
41 if ( isset( $attributes['optionWidth'] ) ) {
42 $css['width'] = ( $attributes['optionWidth'] - 6 ) . '%';
43 }
44 return $css;
45 }
46 public function get_wrapper_css() {
47 return [];
48 }
49 public function get_input_block_main_wrapper( $attributes, $device = '' ) {
50 $css = [];
51 $css['box-sizing'] = 'border-box';
52
53 $valueKey = $device === 'Tablet' ? 'valueTablet' : ( $device === 'Mobile' ? 'valueMobile' : 'value' );
54 $unitKey = $device === 'Tablet' ? 'valueUnitTablet' : ( $device === 'Mobile' ? 'valueUnitMobile' : 'valueUnit' );
55
56 $widthValue = isset( $attributes['inputWidth'][ $valueKey ] ) && $attributes['inputWidth'][ $valueKey ] !== ''
57 ? $attributes['inputWidth'][ $valueKey ]
58 : ( isset( $attributes['inputWidth']['value'] ) ? $attributes['inputWidth']['value'] : 100 );
59
60 $widthUnit = isset( $attributes['inputWidth'][ $unitKey ] ) && $attributes['inputWidth'][ $unitKey ] !== ''
61 ? $attributes['inputWidth'][ $unitKey ]
62 : '%';
63
64 if ( is_numeric( $widthValue ) ) {
65 $widthValue = max( 0, floatval( $widthValue ) - 1 );
66 }
67
68 $css['width'] = $widthValue . $widthUnit;
69
70 return $css;
71 }
72 }
73