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

151 lines 5.2 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\EcmBookmarkBadge;
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\Border;
14 use ABlocks\Controls\Dimensions;
15 use ABlocks\Controls\Range;
16 use ABlocks\Controls\BoxShadow;
17 use ABlocks\Controls\Color;
18
19 class Block extends BlockBaseAbstract {
20 protected $block_name = 'ecm-bookmark-badge';
21
22 public function build_css( $attributes ) {
23 $css_generator = new CssGenerator( $attributes, $this->block_name );
24
25 $css_generator->add_class_styles(
26 '{{WRAPPER}} .ecm-shortcode--bookmark',
27 $this->get_coutineu_button_wrapper_css( $attributes ),
28 $this->get_coutineu_button_wrapper_css( $attributes, 'Tablet' ),
29 $this->get_coutineu_button_wrapper_css( $attributes, 'Mobile' ),
30 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_coutineu_button_wrapper_css( $attributes, $device ); } )
31 );
32 $css_generator->add_class_styles(
33 '{{WRAPPER}} .ecm-shortcode--bookmark svg',
34 $this->get_coutineu_button_css( $attributes ),
35 $this->get_coutineu_button_css( $attributes, 'Tablet' ),
36 $this->get_coutineu_button_css( $attributes, 'Mobile' ),
37 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_coutineu_button_css( $attributes, $device ); } )
38 );
39 $css_generator->add_class_styles(
40 '{{WRAPPER}} .ecm-shortcode--bookmark svg:hover',
41 $this->get_coutineu_button_hover_css( $attributes ),
42 $this->get_coutineu_button_hover_css( $attributes, 'Tablet' ),
43 $this->get_coutineu_button_hover_css( $attributes, 'Mobile' ),
44 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_coutineu_button_hover_css( $attributes, $device ); } )
45 );
46
47 $css_generator->add_class_styles(
48 '{{WRAPPER}} .ecm-shortcode--bookmark 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 return $css_generator->generate_css();
56 }
57
58 public function get_coutineu_button_wrapper_css( $attributes, $device = '' ) {
59 $css = [];
60 $alignment_css = [];
61
62 $css['width'] = '100%';
63 $css['display'] = 'flex';
64 $css['flex-direction'] = 'column';
65
66 if ( ! empty( $attributes['buttonAlignment'][ 'value' . $device ] ) ) {
67 $alignment_css['align-items'] = $attributes['buttonAlignment'][ 'value' . $device ];
68 }
69
70 return array_merge(
71 $alignment_css,
72 $css,
73 );
74
75 }
76
77 public function get_badge_fill_color_css( $attributes ) {
78 $fill_color = Color::get_css( isset( $attributes['badgeFillColor'] ) ? $attributes['badgeFillColor'] : '' );
79 return $fill_color ? [ 'fill' => $fill_color ] : [];
80 }
81
82
83 public function get_coutineu_button_css( $attributes, $device = '' ) {
84 $css = [];
85
86 if ( $attributes['buttonColor'] !== '' ) {
87 $css['color'] = $attributes['buttonColor'];
88 }
89 // if ( $attributes['buttonWidth'] !== '' ) {
90 // $css['width'] = $attributes['buttonWidth'] . '%';
91 // }
92 if ( $attributes['buttonBackground'] !== '' ) {
93 $css['background'] = $attributes['buttonBackground'];
94 }
95
96 if ( ! empty( $attributes['padding'] ) ) {
97 $cssPadding = Dimensions::get_css( $attributes['padding'], 'padding', $device );
98 }
99
100 return array_merge(
101 [ 'color' => Color::get_css( isset( $attributes['buttonColor'] ) ? $attributes['buttonColor'] : '' ) ],
102 [ 'background' => Color::get_css( isset( $attributes['buttonBackground'] ) ? $attributes['buttonBackground'] : '' ) ],
103 $css,
104 Border::get_css( $attributes['buttonBorder'], '', $device ),
105 $cssPadding,
106 BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
107 Range::get_css([
108 'attributeValue' => $attributes['bandageHeight'],
109 'attribute_object_key' => 'value',
110 'isResponsive' => true,
111 'hasUnit' => true,
112 'defaultValue' => 20,
113 'unitDefaultValue' => 'px',
114 'property' => 'height',
115 'device' => $device,
116 ]),
117 Range::get_css([
118 'attributeValue' => $attributes['bandageHeight'],
119 'attribute_object_key' => 'value',
120 'isResponsive' => true,
121 'hasUnit' => true,
122 'defaultValue' => 20,
123 'unitDefaultValue' => 'px',
124 'property' => 'width',
125 'device' => $device,
126 ])
127 );
128 }
129 public function get_coutineu_button_hover_css( $attributes, $device = '' ) {
130 $css = [];
131 return array_merge(
132 $css,
133 [ 'color' => Color::get_css( isset( $attributes['buttonColorH'] ) ? $attributes['buttonColorH'] : '' ) ],
134 [ 'background' => Color::get_css( isset( $attributes['buttonBackgroundH'] ) ? $attributes['buttonBackgroundH'] : '' ) ],
135 Border::get_hover_css( $attributes['buttonBorder'], '', $device ),
136 BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device )
137 );
138 }
139
140 public function render_block_content( $attributes, $content, $block_instance ) {
141 $attr_array = [
142 'id' => Helper::get_attribute_value( $attributes, 'id' ),
143 ];
144
145 $shortcode = '[ecm_bookmark_badge ' . Helper::attr_shortcode( $attr_array ) . ']';
146 echo do_shortcode( $shortcode );
147 }
148
149
150 }
151