PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.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.14.0, at includes/blocks/ecm-claim-badge/block.php

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