| @@ -1,0 +1,58 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace ABlocks\Blocks\Spacer; | |
| 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 | + | |
| 13 | +class Block extends BlockBaseAbstract { | |
| 14 | + protected $block_name = 'spacer'; | |
| 15 | + | |
| 16 | + public function build_css_v1( $attributes ) { | |
| 17 | + $css_generator = new CssGenerator( $attributes, $this->block_name ); | |
| 18 | + | |
| 19 | + $css_generator->add_class_styles( | |
| 20 | + '{{WRAPPER}} .ablocks-spacer__box', | |
| 21 | + $this->get_spacer_css( $attributes ), | |
| 22 | + $this->get_spacer_css( $attributes, 'Tablet' ), | |
| 23 | + $this->get_spacer_css( $attributes, 'Mobile' ), | |
| 24 | + ); | |
| 25 | + | |
| 26 | + return $css_generator->generate_css(); | |
| 27 | + } | |
| 28 | + public function build_css_v2( $attributes ) { | |
| 29 | + $css_generator = new CssGeneratorV2( $attributes, $this->block_name ); | |
| 30 | + | |
| 31 | + $css_generator->add_class_styles( | |
| 32 | + '{{WRAPPER}} .ablocks-spacer__box', | |
| 33 | + $this->get_spacer_css( $attributes ), | |
| 34 | + $this->get_spacer_css( $attributes, 'Tablet' ), | |
| 35 | + $this->get_spacer_css( $attributes, 'Mobile' ), | |
| 36 | + ); | |
| 37 | + | |
| 38 | + return $css_generator->generate_css(); | |
| 39 | + } | |
| 40 | + public function build_css( $attributes ) { | |
| 41 | + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { | |
| 42 | + return $this->build_css_v2( $attributes ); | |
| 43 | + } | |
| 44 | + return $this->build_css_v1( $attributes ); | |
| 45 | + } | |
| 46 | + public function get_spacer_css( $attributes, $device = '' ) { | |
| 47 | + $spacer_css = []; | |
| 48 | + $height = isset( $attributes['spacerHeight'] ) ? $attributes['spacerHeight'] : ''; | |
| 49 | + $height_key = 'value' . $device; | |
| 50 | + | |
| 51 | + if ( ! empty( $height[ $height_key ] ) ) { | |
| 52 | + $value_unit = isset( $height['valueUnit'] ) ? $height['valueUnit'] : 'px'; | |
| 53 | + $spacer_css['height'] = $height[ $height_key ] . $value_unit . '!important'; | |
| 54 | + } | |
| 55 | + | |
| 56 | + return $spacer_css; | |
| 57 | + } | |
| 58 | +} | |