← All changes
|
includes/blocks/storeengine-continue-button/block.php
+125
-0
2.7.7
→
2.13.0
View file →
| @@ -1,0 +1,125 @@ | ||
| 1 | +<?php | |
| 2 | +namespace ABlocks\Blocks\StoreengineContinueButton; | |
| 3 | + | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 8 | +use ABlocks\Classes\BlockBaseAbstract; | |
| 9 | +use ABlocks\Classes\CssGenerator; | |
| 10 | +use ABlocks\Helper; | |
| 11 | +use ABlocks\Controls\Typography; | |
| 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 = 'storeengine-continue-button'; | |
| 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}} .storeengine-continue-shopping-shortcode', | |
| 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 | + ); | |
| 31 | + $css_generator->add_class_styles( | |
| 32 | + '{{WRAPPER}} .storeengine-continue-shopping-shortcode a', | |
| 33 | + $this->get_coutineu_button_css( $attributes ), | |
| 34 | + $this->get_coutineu_button_css( $attributes, 'Tablet' ), | |
| 35 | + $this->get_coutineu_button_css( $attributes, 'Mobile' ) | |
| 36 | + ); | |
| 37 | + $css_generator->add_class_styles( | |
| 38 | + '{{WRAPPER}} .storeengine-continue-shopping-shortcode a:hover', | |
| 39 | + $this->get_coutineu_button_hover_css( $attributes ), | |
| 40 | + $this->get_coutineu_button_hover_css( $attributes, 'Tablet' ), | |
| 41 | + $this->get_coutineu_button_hover_css( $attributes, 'Mobile' ) | |
| 42 | + ); | |
| 43 | + | |
| 44 | + return $css_generator->generate_css(); | |
| 45 | + } | |
| 46 | + public function get_coutineu_button_wrapper_css( $attributes, $device = '' ) { | |
| 47 | + $css = []; | |
| 48 | + $alignment_css = []; | |
| 49 | + | |
| 50 | + $css['width'] = '100%'; | |
| 51 | + $css['display'] = 'flex'; | |
| 52 | + | |
| 53 | + if ( ! empty( $attributes['buttonAlignment'][ 'value' . $device ] ) ) { | |
| 54 | + $alignment_css['justify-content'] = $attributes['buttonAlignment'][ 'value' . $device ]; | |
| 55 | + } | |
| 56 | + | |
| 57 | + return array_merge( | |
| 58 | + $alignment_css, | |
| 59 | + $css, | |
| 60 | + ); | |
| 61 | + | |
| 62 | + } | |
| 63 | + | |
| 64 | + public function get_coutineu_button_css( $attributes, $device = '' ) { | |
| 65 | + $css = []; | |
| 66 | + | |
| 67 | + if ( $attributes['buttonColor'] !== '' ) { | |
| 68 | + $css['color'] = $attributes['buttonColor']; | |
| 69 | + } | |
| 70 | + // if ( $attributes['buttonWidth'] !== '' ) { | |
| 71 | + // $css['width'] = $attributes['buttonWidth'] . '%'; | |
| 72 | + // } | |
| 73 | + if ( $attributes['buttonBackground'] !== '' ) { | |
| 74 | + $css['background'] = $attributes['buttonBackground']; | |
| 75 | + } | |
| 76 | + $typography = isset( $attributes['buttonTypography'] ) && is_array( $attributes['buttonTypography'] ) | |
| 77 | + ? $attributes['buttonTypography'] | |
| 78 | + : []; | |
| 79 | + $typographyValueGlobal = ( isset( $attributes['buttonTypographyGlobal'] ) ? $attributes['buttonTypographyGlobal'] : '' ); | |
| 80 | + | |
| 81 | + $typography_value = array_merge( $typography, [ 'font-weight' => '400' ] ); | |
| 82 | + | |
| 83 | + if ( ! empty( $attributes['padding'] ) ) { | |
| 84 | + $cssPadding = Dimensions::get_css( $attributes['padding'], 'padding', $device ); | |
| 85 | + } | |
| 86 | + | |
| 87 | + return array_merge( | |
| 88 | + [ 'color' => Color::get_css( isset( $attributes['buttonColor'] ) ? $attributes['buttonColor'] : '' ) ], | |
| 89 | + [ 'background' => Color::get_css( isset( $attributes['buttonBackground'] ) ? $attributes['buttonBackground'] : '' ) ], | |
| 90 | + $css, | |
| 91 | + Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ), | |
| 92 | + Border::get_css( $attributes['buttonBorder'], '', $device ), | |
| 93 | + $cssPadding, | |
| 94 | + BoxShadow::get_css( $attributes['boxShadow'], '', $device ), | |
| 95 | + Range::get_css([ | |
| 96 | + 'attributeValue' => $attributes['buttonWidth'], | |
| 97 | + 'attribute_object_key' => 'value', | |
| 98 | + 'isResponsive' => true, | |
| 99 | + 'hasUnit' => true, | |
| 100 | + 'defaultValue' => 100, | |
| 101 | + 'unitDefaultValue' => '%', | |
| 102 | + 'property' => 'width', | |
| 103 | + 'device' => $device, | |
| 104 | + ]) | |
| 105 | + ); | |
| 106 | + } | |
| 107 | + | |
| 108 | + public function get_coutineu_button_hover_css( $attributes, $device = '' ) { | |
| 109 | + return array_merge( | |
| 110 | + [ 'color' => Color::get_css( isset( $attributes['buttonColorH'] ) ? $attributes['buttonColorH'] : '' ) ], | |
| 111 | + [ 'background' => Color::get_css( isset( $attributes['buttonBackgroundH'] ) ? $attributes['buttonBackgroundH'] : '' ) ], | |
| 112 | + Border::get_hover_css( $attributes['buttonBorder'] ?? [], '', $device ), | |
| 113 | + BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device ), | |
| 114 | + ); | |
| 115 | + | |
| 116 | + } | |
| 117 | + public function render_block_content( $attributes, $content, $block_instance ) { | |
| 118 | + $attr_array = [ | |
| 119 | + // 'ids' => Helper::get_attribute_value( $attributes, 'products_ids' ), | |
| 120 | + ]; | |
| 121 | + $shortcode = '[storeengine_continue_shopping ' . Helper::attr_shortcode( $attr_array ) . ']'; | |
| 122 | + echo do_shortcode( $shortcode ); | |
| 123 | + } | |
| 124 | + | |
| 125 | +} | |