PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.10.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.10.0
2.14.0 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 All 81 releases
ablocks / includes / blocks / ecm-claim-badge / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.10.0, at includes/blocks/ecm-claim-badge/block.php

192 lines 6.0 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\EcmClaimBadge;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use ABlocks\Classes\BlockBaseAbstract;
10 use ABlocks\Classes\CssGenerator;
11 use ABlocks\Helper;
12 use ABlocks\Controls\Background;
13 use ABlocks\Controls\Typography;
14 use ABlocks\Controls\Border;
15 use ABlocks\Controls\Dimensions;
16 use ABlocks\Controls\Range;
17 use ABlocks\Controls\BoxShadow;
18 use ABlocks\Controls\Color;
19
20 class Block extends BlockBaseAbstract {
21 protected $block_name = 'ecm-claim-badge';
22
23 public function build_css( $attributes ) {
24 $css_generator = new CssGenerator( $attributes, $this->block_name );
25
26 $css_generator->add_class_styles(
27 '{{WRAPPER}} .ecm-shortcode--claim-badge',
28 $this->get_coutineu_button_wrapper_css( $attributes ),
29 $this->get_coutineu_button_wrapper_css( $attributes, 'Tablet' ),
30 $this->get_coutineu_button_wrapper_css( $attributes, 'Mobile' )
31 );
32 $css_generator->add_class_styles(
33 '{{WRAPPER}} .ecm-shortcode--claim-badge__badge-text',
34 $this->get_coutineu_button_with_text( $attributes ),
35 $this->get_coutineu_button_with_text( $attributes, 'Tablet' ),
36 $this->get_coutineu_button_with_text( $attributes, 'Mobile' )
37 );
38 $css_generator->add_class_styles(
39 '{{WRAPPER}} .ecm-shortcode--claim-badge svg',
40 $this->get_coutineu_button_css( $attributes ),
41 $this->get_coutineu_button_css( $attributes, 'Tablet' ),
42 $this->get_coutineu_button_css( $attributes, 'Mobile' )
43 );
44 $css_generator->add_class_styles(
45 '{{WRAPPER}} .ecm-shortcode--claim-badge svg path',
46 $this->get_badge_fill_color_css( $attributes ),
47 $this->get_badge_fill_color_css($attributes, 'Tablet'),
48 $this->get_badge_fill_color_css($attributes, 'Mobile')
49 );
50
51 $css_generator->add_class_styles(
52 '{{WRAPPER}} .ecm-shortcode--claim-badge:hover svg',
53 $this->get_coutineu_button_hover_css( $attributes ),
54 $this->get_coutineu_button_hover_css( $attributes, 'Tablet' ),
55 $this->get_coutineu_button_hover_css( $attributes, 'Mobile' )
56 );
57
58 return $css_generator->generate_css();
59 }
60
61 public function get_coutineu_button_wrapper_css( $attributes, $device = '' ) {
62 $css = [];
63 $alignment_css = [];
64
65 $css['width'] = '100%';
66 $css['display'] = 'flex';
67 $css['align-items'] = 'center';
68
69 if ( ! empty( $attributes['buttonAlignment'][ 'value' . $device ] ) ) {
70 $alignment_css['justify-content'] = $attributes['buttonAlignment'][ 'value' . $device ];
71 }
72
73 return array_merge(
74 $alignment_css,
75 $css,
76 Range::get_css([
77 'attributeValue' => $attributes['textGap'],
78 'attribute_object_key' => 'value',
79 'isResponsive' => true,
80 'hasUnit' => true,
81 'defaultValue' => 10,
82 'unitDefaultValue' => 'px',
83 'property' => 'gap',
84 'device' => $device,
85 ]),
86 );
87
88 }
89
90 public function get_coutineu_button_css( $attributes, $device = '' ) {
91 $css = [];
92
93 if ( $attributes['buttonColor'] !== '' ) {
94 $css['color'] = $attributes['buttonColor'];
95 }
96 if ( $attributes['buttonBackground'] !== '' ) {
97 $css['background'] = $attributes['buttonBackground'];
98 }
99
100 if ( ! empty( $attributes['padding'] ) ) {
101 $cssPadding = Dimensions::get_css( $attributes['padding'], 'padding', $device );
102 }
103
104 return array_merge(
105 [ 'color' => Color::get_css( isset( $attributes['buttonColor'] ) ? $attributes['buttonColor'] : '' ) ],
106 [ 'background' => Color::get_css( isset( $attributes['buttonBackground'] ) ? $attributes['buttonBackground'] : '' ) ],
107 $css,
108 Border::get_css( $attributes['buttonBorder'], '', $device ),
109 $cssPadding,
110 BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
111 Range::get_css([
112 'attributeValue' => $attributes['bandageHeight'],
113 'attribute_object_key' => 'value',
114 'isResponsive' => true,
115 'hasUnit' => true,
116 'defaultValue' => 20,
117 'unitDefaultValue' => 'px',
118 'property' => 'height',
119 'device' => $device,
120 ]),
121 Range::get_css([
122 'attributeValue' => $attributes['bandageHeight'],
123 'attribute_object_key' => 'value',
124 'isResponsive' => true,
125 'hasUnit' => true,
126 'defaultValue' => 20,
127 'unitDefaultValue' => 'px',
128 'property' => 'width',
129 'device' => $device,
130 ])
131 );
132 }
133 public function get_coutineu_button_with_text( $attributes, $device = '' ) {
134 $css = [];
135
136 if ( $attributes['textColor'] !== '' ) {
137 $css['color'] = $attributes['textColor'];
138 }
139
140 $typography = isset( $attributes['textTypography'] ) && is_array( $attributes['textTypography'] )
141 ? $attributes['textTypography']
142 : [];
143 $typographyValueGlobal = ( isset( $attributes['textTypographyGlobal'] ) ? $attributes['textTypographyGlobal'] : '' );
144
145 $typography_value = array_merge( $typography, [ 'font-weight' => '400' ] );
146
147 return array_merge(
148 $css,
149 Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ),
150 [ 'color' => Color::get_css( isset( $attributes['textColor'] ) ? $attributes['textColor'] : '' ) ],
151 );
152 }
153
154 public function get_badge_fill_color_css( $attributes ) {
155 $fill_color = Color::get_css( isset( $attributes['badgeFillColor'] ) ? $attributes['badgeFillColor'] : '' );
156 return $fill_color ? [ 'fill' => $fill_color ] : [];
157 }
158
159
160 public function get_coutineu_button_hover_css( $attributes, $device = '' ) {
161 $button_border = array_merge(
162 [ 'unitWidthH' => 'px', 'unitRadiusH' => 'px' ],
163 $attributes['buttonBorder'] ?? []
164 );
165
166 return array_merge(
167 [ 'color' => Color::get_css( $attributes['buttonColorH'] ?? '' ) ],
168 [ 'background' => Color::get_css( $attributes['buttonBackgroundH'] ?? '' ) ],
169 Border::get_hover_css( $button_border, '', $device ),
170 BoxShadow::get_hover_css( $attributes['boxShadow'] ?? [], $device )
171 );
172 }
173
174 public function get_coutineu_button_text_hover_css( $attributes, $device = '' ) {
175 return [
176 'color' => Color::get_css( $attributes['textColorH'] ?? '' ),
177 ];
178 }
179
180 public function render_block_content( $attributes, $content, $block_instance ) {
181 $attr_array = [
182 'post_id' => Helper::get_attribute_value( $attributes, 'post_id' ),
183 'text' => Helper::get_attribute_value( $attributes, 'text' ),
184 ];
185
186 $shortcode = '[ecm_claim_badge ' . Helper::attr_shortcode( $attr_array ) . ']';
187 echo do_shortcode( $shortcode );
188 }
189
190
191 }
192