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-button / 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-button/block.php

187 lines 7.7 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\EcmClaimButton;
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\Typography;
13 use ABlocks\Controls\Background;
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 use ABlocks\Controls\Alignment;
20
21
22 class Block extends BlockBaseAbstract {
23 protected $block_name = 'ecm-claim-button';
24
25 public function build_css( $attributes ) {
26 $css_generator = new CssGenerator( $attributes, $this->block_name );
27
28 $css_generator->add_class_styles(
29 '{{WRAPPER}} .ecm-shortcode--claim',
30 $this->get_coutineu_button_wrapper_css( $attributes ),
31 $this->get_coutineu_button_wrapper_css( $attributes, 'Tablet' ),
32 $this->get_coutineu_button_wrapper_css( $attributes, 'Mobile' ),
33 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_coutineu_button_wrapper_css( $attributes, $device ); } )
34 );
35 $css_generator->add_class_styles(
36 '{{WRAPPER}} .ecm-shortcode--claim button',
37 $this->get_coutineu_button_css( $attributes ),
38 $this->get_coutineu_button_css( $attributes, 'Tablet' ),
39 $this->get_coutineu_button_css( $attributes, 'Mobile' ),
40 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_coutineu_button_css( $attributes, $device ); } )
41 );
42 $css_generator->add_class_styles(
43 '{{WRAPPER}} .ecm-shortcode--claim button:hover',
44 $this->get_coutineu_button_hover_css( $attributes ),
45 $this->get_coutineu_button_hover_css( $attributes, 'Tablet' ),
46 $this->get_coutineu_button_hover_css( $attributes, 'Mobile' ),
47 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_coutineu_button_hover_css( $attributes, $device ); } )
48 );
49 foreach ( [ '.ecm-shortcode--tooltip', '.ecm-shortcode--tooltip svg', '.ecm-shortcode--tooltip svg path' ] as $selector ) {
50 $css_generator->add_class_styles(
51 '{{WRAPPER}} ' . $selector,
52 $this->get_badge_css( $attributes, 'pendingBadgeFillColor', 'pendingBadgeSize' ),
53 $this->get_badge_css( $attributes, 'pendingBadgeFillColor', 'pendingBadgeSize', 'Tablet' ),
54 $this->get_badge_css( $attributes, 'pendingBadgeFillColor', 'pendingBadgeSize', 'Mobile' ),
55 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_badge_css( $attributes, 'pendingBadgeFillColor', 'pendingBadgeSize', $device ); } )
56 );
57 }
58 $css_generator->add_class_styles(
59 '{{WRAPPER}}.ablocks-block--ecm-claim-button',
60 $this->get_list_alignment_css( $attributes ),
61 $this->get_list_alignment_css( $attributes, 'Tablet' ),
62 $this->get_list_alignment_css( $attributes, 'Mobile' ),
63 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_list_alignment_css( $attributes, $device ); } )
64 );
65 foreach ( [ '.ecm-shortcode--claim__message', '.ecm-shortcode--claim__message svg', '.ecm-shortcode--claim__message svg path' ] as $selector ) {
66 $css_generator->add_class_styles(
67 '{{WRAPPER}} ' . $selector,
68 $this->get_badge_css( $attributes, 'confirmationBandageFillColor', 'confirmationBandageSize', '', true ),
69 $this->get_badge_css( $attributes, 'confirmationBandageFillColor', 'confirmationBandageSize', 'Tablet', true ),
70 $this->get_badge_css( $attributes, 'confirmationBandageFillColor', 'confirmationBandageSize', 'Mobile', true ),
71 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_badge_css( $attributes, 'confirmationBandageFillColor', 'confirmationBandageSize', $device, true ); } )
72 );
73 }
74
75 return $css_generator->generate_css();
76 }
77
78 public function get_coutineu_button_wrapper_css( $attributes, $device = '' ) {
79 $css = [];
80 $alignment_css = [];
81 $css['display'] = 'flex';
82
83 if ( ! empty( $attributes['buttonAlignment'][ 'value' . $device ] ) ) {
84 $alignment_css['justify-content'] = $attributes['buttonAlignment'][ 'value' . $device ];
85 }
86
87 return array_merge(
88 $alignment_css,
89 $css,
90 );
91
92 }
93
94 public function get_coutineu_button_css( $attributes, $device = '' ) {
95 $css = [];
96
97 if ( $attributes['buttonColor'] !== '' ) {
98 $css['color'] = $attributes['buttonColor'];
99 }
100 if ( $attributes['buttonBackground'] !== '' ) {
101 $css['background'] = $attributes['buttonBackground'];
102 }
103 $typography = isset( $attributes['buttonTypography'] ) && is_array( $attributes['buttonTypography'] )
104 ? $attributes['buttonTypography']
105 : [];
106 $typographyValueGlobal = ( isset( $attributes['buttonTypographyGlobal'] ) ? $attributes['buttonTypographyGlobal'] : '' );
107
108 $typography_value = array_merge( $typography, [ 'font-weight' => '400' ] );
109
110 $cssPadding = ! empty( $attributes['padding'] ) ? Dimensions::get_css( $attributes['padding'], 'padding', $device ) : [];
111
112 return array_merge(
113 [ 'color' => Color::get_css( isset( $attributes['buttonColor'] ) ? $attributes['buttonColor'] : '' ) ],
114 [ 'background' => Color::get_css( isset( $attributes['buttonBackground'] ) ? $attributes['buttonBackground'] : '' ) ],
115 $css,
116 Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ),
117 Border::get_css( $attributes['buttonBorder'], '', $device ),
118 $cssPadding,
119 BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
120 );
121 }
122
123 public function get_coutineu_button_hover_css( $attributes, $device = '' ) {
124 $hover_css = array_merge(
125 [ 'color' => Color::get_css( isset( $attributes['buttonColorH'] ) ? $attributes['buttonColorH'] : '' ) ],
126 [ 'background' => Color::get_css( isset( $attributes['buttonBackgroundH'] ) ? $attributes['buttonBackgroundH'] : '' ) ],
127 Border::get_hover_css( $attributes['buttonBorder'] ?? [], '', $device ),
128 BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device ),
129 );
130
131 if ( ! empty( $hover_css['box-shadow'] ) ) {
132 $hover_css['box-shadow'] = $hover_css['box-shadow'] . ' !important';
133 } else {
134 $normal_shadow = BoxShadow::get_css( $attributes['boxShadow'], '', $device );
135 if ( ! empty( $normal_shadow['box-shadow'] ) ) {
136 $hover_css['box-shadow'] = $normal_shadow['box-shadow'] . ' !important';
137 }
138 }
139
140 return $hover_css;
141 }
142
143 public function get_badge_css( $attributes, $fill_key, $size_key, $device = '', $transparent_bg = false ) {
144 $base = [ 'fill' => Color::get_css( $attributes[ $fill_key ] ?? '' ) ];
145 if ( $transparent_bg ) {
146 $base['background'] = 'transparent';
147 }
148 $size_args = [
149 'attributeValue' => $attributes[ $size_key ],
150 'attribute_object_key' => 'value',
151 'isResponsive' => true,
152 'hasUnit' => true,
153 'defaultValue' => 20,
154 'unitDefaultValue' => 'px',
155 'device' => $device,
156 ];
157 return array_merge(
158 $base,
159 Range::get_css( array_merge( $size_args, [ 'property' => 'height' ] ) ),
160 Range::get_css( array_merge( $size_args, [ 'property' => 'width' ] ) )
161 );
162 }
163
164 public function get_list_alignment_css( $attributes, $device = '' ) {
165 $css = [ 'display' => 'flex', 'align-items' => 'center' ];
166 $alignment_css = [];
167
168 if ( ! empty( $attributes['listAlignment'][ 'value' . $device ] ) ) {
169 $alignment_css['justify-content'] = $attributes['listAlignment'][ 'value' . $device ];
170 }
171 return array_merge( $alignment_css, $css );
172 }
173
174
175 public function render_block_content( $attributes, $content, $block_instance ) {
176 $attr_array = [
177 'bookmark_text' => Helper::get_attribute_value( $attributes, 'bookmark_text' ),
178 'bookmarked_text' => Helper::get_attribute_value( $attributes, 'bookmarked_text' ),
179 'id' => Helper::get_attribute_value( $attributes, 'id' ),
180 ];
181
182 $shortcode = '[ecm_claim_button ' . Helper::attr_shortcode( $attr_array ) . ']';
183 echo do_shortcode( $shortcode );
184 }
185
186 }
187