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
← All changes | includes/blocks/storeengine-mini-cart/block.php +124 -0 2.7.4 → 2.14.0 View file →
@@ -1,0 +1,124 @@
1 +<?php
2 +
3 +namespace ABlocks\Blocks\StoreengineMiniCart;
4 +
5 +if ( ! defined( 'ABSPATH' ) ) {
6 + exit;
7 +}
8 +
9 +use ABlocks\Classes\BlockBaseAbstract;
10 +use ABlocks\Classes\CssGenerator;
11 +use ABlocks\Classes\CssGeneratorV2;
12 +use ABlocks\Helper;
13 +use ABlocks\Controls\Typography;
14 +use ABlocks\Controls\Background;
15 +use ABlocks\Controls\Border;
16 +use ABlocks\Controls\Dimensions;
17 +use ABlocks\Controls\Range;
18 +use ABlocks\Controls\Color;
19 +
20 +class Block extends BlockBaseAbstract {
21 + protected $block_name = 'storeengine-mini-cart';
22 +
23 + public function build_css_v1( $attributes ) {
24 + $css_generator = new CssGenerator( $attributes );
25 + return $css_generator->generate_css();
26 + }
27 +
28 + public function build_css_v2( $attributes ) {
29 + $css_generator = new CssGenerator( $attributes, $this->block_name );
30 +
31 + $css_generator->add_class_styles(
32 + '{{WRAPPER}} .storeengine-mini-cart-link svg',
33 + $this->get_icon_button_css( $attributes, '' ),
34 + $this->get_icon_button_css( $attributes, 'Tablet' ),
35 + $this->get_icon_button_css( $attributes, 'Mobile' ),
36 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icon_button_css( $attributes, $device ); } )
37 + );
38 + $css_generator->add_class_styles(
39 + '{{WRAPPER}} .storeengine-mini-cart',
40 + $this->get_wrapper_css( $attributes, '' ),
41 + $this->get_wrapper_css( $attributes, 'Tablet' ),
42 + $this->get_wrapper_css( $attributes, 'Mobile' ),
43 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } )
44 + );
45 + $css_generator->add_class_styles(
46 + '{{WRAPPER}} .storeengine-mini-cart-link svg:hover',
47 + $this->get_icon_button_hover_css( $attributes, '' ),
48 + $this->get_icon_button_hover_css( $attributes, 'Tablet' ),
49 + $this->get_icon_button_hover_css( $attributes, 'Mobile' ),
50 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icon_button_hover_css( $attributes, $device ); } )
51 + );
52 + $css_generator->add_class_styles(
53 + '{{WRAPPER}} .storeengine-mini-cart>button.storeengine-mini-cart-link>.storeengine-min-cart-count',
54 + $this->get_icon_text_css( $attributes, '' ),
55 + $this->get_icon_text_css( $attributes, 'Tablet' ),
56 + $this->get_icon_text_css( $attributes, 'Mobile' ),
57 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icon_text_css( $attributes, $device ); } )
58 + );
59 + $css_generator->add_class_styles(
60 + '{{WRAPPER}} .storeengine-mini-cart>button.storeengine-mini-cart-link>.storeengine-min-cart-count:hover',
61 + $this->get_icon_text_hover_css( $attributes, '' ),
62 + $this->get_icon_text_hover_css( $attributes, 'Tablet' ),
63 + $this->get_icon_text_hover_css( $attributes, 'Mobile' ),
64 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icon_text_hover_css( $attributes, $device ); } )
65 + );
66 +
67 + return $css_generator->generate_css();
68 + }
69 +
70 + public function build_css( $attributes ) {
71 + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
72 + return $this->build_css_v2( $attributes );
73 + }
74 + return $this->build_css_v1( $attributes );
75 + }
76 +
77 + public function get_icon_button_css( $attributes, $device = '' ) {
78 + return array_merge(
79 + [ 'color' => Color::get_css( isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '' ) ],
80 + );
81 + }
82 +
83 + public function get_icon_button_hover_css( $attributes, $device = '' ) {
84 + return [ 'color' => Color::get_css( isset( $attributes['iconColorH'] ) ? $attributes['iconColorH'] : '' ) ];
85 +
86 + }
87 + public function get_icon_text_css( $attributes, $device = '' ) {
88 + $typographyValueGlobal = ! empty( $attributes['countTypographyGlobal'] ) ? $attributes['countTypographyGlobal'] : '';
89 + $typography_css = isset( $attributes['countTypography'] )
90 + ? Typography::get_css( $attributes['countTypography'], '', $device, $typographyValueGlobal )
91 + : [];
92 +
93 + return array_merge(
94 + $typography_css,
95 + [ 'color' => Color::get_css( isset( $attributes['countColor'] ) ? $attributes['countColor'] : '' ) ],
96 + [ 'background' => Color::get_css( isset( $attributes['countBg'] ) ? $attributes['countBg'] : '' ) ],
97 + );
98 + }
99 +
100 + public function get_wrapper_css( $attributes, $device = '' ) {
101 + $css_padding = [];
102 +
103 + if ( ! empty( $attributes['padding'] ) ) {
104 + $css_padding = Dimensions::get_css( $attributes['padding'], 'padding', $device );
105 + }
106 +
107 + return $css_padding;
108 + }
109 +
110 + public function get_icon_text_hover_css( $attributes, $device = '' ) {
111 + return array_merge(
112 + [ 'color' => Color::get_css( isset( $attributes['countColorH'] ) ? $attributes['countColorH'] : '' ) ],
113 + [ 'background' => Color::get_css( isset( $attributes['countBgH'] ) ? $attributes['countBgH'] : '' ) ],
114 + );
115 + }
116 +
117 + public function render_block_content( $attributes, $content, $block_instance ) {
118 + $attr_array = [];
119 +
120 + $shortcode = '[storeengine_mini_cart ' . Helper::attr_shortcode( $attr_array ) . ']';
121 + echo do_shortcode( $shortcode );
122 + }
123 +
124 +}