| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\PriceMenuItem; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
use ABlocks\Classes\BlockBaseAbstract; |
| 9 |
use ABlocks\Classes\CssGenerator; |
| 10 |
use ABlocks\Controls\Icon; |
| 11 |
use ABlocks\Controls\Alignment; |
| 12 |
use ABlocks\Controls\Typography; |
| 13 |
use ABlocks\Controls\TextShadow; |
| 14 |
use ABlocks\Controls\TextStroke; |
| 15 |
use ABlocks\Controls\Range; |
| 16 |
use ABlocks\Controls\Color; |
| 17 |
|
| 18 |
class Block extends BlockBaseAbstract { |
| 19 |
protected $parent_block_name = 'price-menu'; |
| 20 |
protected $block_name = 'price-menu-item'; |
| 21 |
|
| 22 |
public function build_css( $attributes ) { |
| 23 |
|
| 24 |
$css_generator = new CssGenerator( $attributes, $this->block_name ); |
| 25 |
// Icon Style |
| 26 |
$css_generator->add_class_styles( |
| 27 |
'{{WRAPPER}} .ablocks-icon-wrap', |
| 28 |
Icon::get_wrapper_css( $attributes ), |
| 29 |
Icon::get_wrapper_css( $attributes, 'Tablet' ), |
| 30 |
Icon::get_wrapper_css( $attributes, 'Mobile' ) |
| 31 |
); |
| 32 |
$css_generator->add_class_styles( |
| 33 |
'{{WRAPPER}} .ablocks-icon-wrap:hover', |
| 34 |
Icon::get_wrapper_hover_css( $attributes ), |
| 35 |
Icon::get_wrapper_hover_css( $attributes, 'Tablet' ), |
| 36 |
Icon::get_wrapper_hover_css( $attributes, 'Mobile' ) |
| 37 |
); |
| 38 |
$css_generator->add_class_styles( |
| 39 |
'{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon', |
| 40 |
Icon::get_element_image_css( $attributes ), |
| 41 |
Icon::get_element_image_css( $attributes, 'Tablet' ), |
| 42 |
Icon::get_element_image_css( $attributes, 'Mobile' ), |
| 43 |
); |
| 44 |
$css_generator->add_class_styles( |
| 45 |
'{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover', |
| 46 |
Icon::get_element_image_hover_css( $attributes ), |
| 47 |
Icon::get_element_image_hover_css( $attributes, 'Tablet' ), |
| 48 |
Icon::get_element_image_hover_css( $attributes, 'Mobile' ), |
| 49 |
); |
| 50 |
$css_generator->add_class_styles( |
| 51 |
'{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon', |
| 52 |
Icon::get_element_css( $attributes ), |
| 53 |
Icon::get_element_css( $attributes, 'Tablet' ), |
| 54 |
Icon::get_element_css( $attributes, 'Mobile' ), |
| 55 |
); |
| 56 |
$css_generator->add_class_styles( |
| 57 |
'{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover', |
| 58 |
Icon::get_element_image_hover_css( $attributes ), |
| 59 |
Icon::get_element_image_hover_css( $attributes, 'Tablet' ), |
| 60 |
Icon::get_element_image_hover_css( $attributes, 'Mobile' ), |
| 61 |
); |
| 62 |
// TitleText CSS |
| 63 |
$css_generator->add_class_styles( |
| 64 |
'{{WRAPPER}} .ablocks-price-menu-item-details-title', |
| 65 |
$this->get_title_text_css( $attributes, '' ), |
| 66 |
$this->get_title_text_css( $attributes, 'Tablet' ), |
| 67 |
$this->get_title_text_css( $attributes, 'Mobile' ), |
| 68 |
); |
| 69 |
// DescriptionText CSS |
| 70 |
$css_generator->add_class_styles( |
| 71 |
'{{WRAPPER}} .ablocks-price-menu-item-details-des', |
| 72 |
$this->get_description_text_css( $attributes, '' ), |
| 73 |
$this->get_description_text_css( $attributes, 'Tablet' ), |
| 74 |
$this->get_description_text_css( $attributes, 'Mobile' ), |
| 75 |
); |
| 76 |
// SeparatorText CSS |
| 77 |
$css_generator->add_class_styles( |
| 78 |
'{{WRAPPER}} .ablocks-price-menu-divider__pattern-' . ( $attributes['dividerType'] === 'mask-style' ? 'mask' : 'css' ), |
| 79 |
$this->get_divider_css( $attributes, '' ), |
| 80 |
$this->get_divider_css( $attributes, 'Tablet' ), |
| 81 |
$this->get_divider_css( $attributes, 'Mobile' ), |
| 82 |
); |
| 83 |
// PriceText CSS |
| 84 |
$css_generator->add_class_styles( |
| 85 |
'{{WRAPPER}} .ablocks-price-menu-item-price', |
| 86 |
$this->get_price_text_css( $attributes, '' ), |
| 87 |
$this->get_price_text_css( $attributes, 'Tablet' ), |
| 88 |
$this->get_price_text_css( $attributes, 'Mobile' ), |
| 89 |
); |
| 90 |
|
| 91 |
return $css_generator->generate_css(); |
| 92 |
} |
| 93 |
|
| 94 |
public function get_title_text_css( $attributes, $device = '' ) { |
| 95 |
$typographyValueGlobal = ! empty( $attributes['titleTypographyGlobal'] ) ? $attributes['titleTypographyGlobal'] : array(); |
| 96 |
return array_merge( |
| 97 |
[ 'color' => Color::get_css( isset( $attributes['titleColor'] ) ? $attributes['titleColor'] : '' ) ], |
| 98 |
isset( $attributes['titleTypography'] ) ? Typography::get_css( $attributes['titleTypography'], '', $device, $typographyValueGlobal ) : [], |
| 99 |
isset( $attributes['titleTextStroke'] ) ? TextStroke::get_css( $attributes['titleTextStroke'], '', $device ) : [], |
| 100 |
isset( $attributes['titleTextShadow'] ) ? TextShadow::get_css( $attributes['titleTextShadow'], '', $device ) : [], |
| 101 |
isset( $attributes['titleAlignment'] ) ? Alignment::get_css( $attributes['titleAlignment'], 'text-align', $device ) : [], |
| 102 |
); |
| 103 |
} |
| 104 |
public function get_description_text_css( $attributes, $device = '' ) { |
| 105 |
$typographyValueGlobal = ! empty( $attributes['descriptionTypographyGlobal'] ) ? $attributes['descriptionTypographyGlobal'] : array(); |
| 106 |
|
| 107 |
return array_merge( |
| 108 |
[ 'color' => Color::get_css( isset( $attributes['descriptionColor'] ) ? $attributes['descriptionColor'] : '' ) ], |
| 109 |
isset( $attributes['descriptionTypography'] ) ? Typography::get_css( $attributes['descriptionTypography'], '', $device, $typographyValueGlobal ) : [], |
| 110 |
isset( $attributes['descriptionTextStroke'] ) ? TextStroke::get_css( $attributes['descriptionTextStroke'], '', $device ) : [], |
| 111 |
isset( $attributes['descriptionTextShadow'] ) ? TextShadow::get_css( $attributes['descriptionTextShadow'], '', $device ) : [], |
| 112 |
isset( $attributes['descriptionAlignment'] ) ? Alignment::get_css( $attributes['descriptionAlignment'], 'text-align', $device ) : [], |
| 113 |
); |
| 114 |
} |
| 115 |
public function get_divider_css( $attributes, $device = '' ) { |
| 116 |
$css = []; |
| 117 |
$divider_width = isset( $attributes['width'][ 'value' . $device ] ) ? $attributes['width'][ 'value' . $device ] : 60; |
| 118 |
$default_Unit = $attributes['allowDescription'] === true ? '%' : 'px'; |
| 119 |
|
| 120 |
if ( ! empty( $attributes['color'] ) ) { |
| 121 |
$css['--ablocks-divider-pattern-color'] = Color::get_css( |
| 122 |
isset( $attributes['color'] ) ? $attributes['color'] : '#000000'); |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
$moreRangeCSS = []; |
| 127 |
if ( isset( $attributes['dividerType'] ) && $attributes['dividerType'] === 'mask-style' && isset( $attributes['size'] ) && ! empty( $attributes['size'] ) ) { |
| 128 |
$moreRangeCSS = Range::get_css([ |
| 129 |
'attributeValue' => $attributes['size'], |
| 130 |
'attribute_object_key' => 'value', |
| 131 |
'isResponsive' => false, |
| 132 |
'defaultValue' => null, |
| 133 |
'hasUnit' => false, |
| 134 |
'unitDefaultValue' => 'px', |
| 135 |
'property' => '--ablocks-divider-pattern-height', |
| 136 |
]); |
| 137 |
} elseif ( isset( $attributes['weight'] ) && ! empty( $attributes['weight'] ) ) { |
| 138 |
$moreRangeCSS = Range::get_css([ |
| 139 |
'attributeValue' => $attributes['weight'], |
| 140 |
'attribute_object_key' => 'value', |
| 141 |
'isResponsive' => false, |
| 142 |
'defaultValue' => null, |
| 143 |
'hasUnit' => false, |
| 144 |
'unitDefaultValue' => 'px', |
| 145 |
'property' => '--ablocks-divider-pattern-weight', |
| 146 |
]); |
| 147 |
}//end if |
| 148 |
|
| 149 |
if ( ! empty( $attributes['dividerPatternUrl'] ) ) { |
| 150 |
if ( $attributes['dividerType'] === 'mask-style' ) { |
| 151 |
$css['--ablocks-divider-pattern-url'] = 'url(' . $attributes['dividerPatternUrl'] . ')'; |
| 152 |
} else { |
| 153 |
$css['--ablocks-divider-pattern-style'] = $attributes['dividerPatternUrl']; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
return array_merge( |
| 158 |
$css, |
| 159 |
Range::get_css([ |
| 160 |
'attributeValue' => $attributes['width'], |
| 161 |
'attribute_object_key' => 'value', |
| 162 |
'isResponsive' => true, |
| 163 |
'defaultValue' => null, |
| 164 |
'hasUnit' => false, |
| 165 |
'unitDefaultValue' => $attributes['allowDescription'] === true ? '%' : 'px', |
| 166 |
'property' => 'width', |
| 167 |
'device' => $device, |
| 168 |
]), |
| 169 |
$moreRangeCSS, |
| 170 |
); |
| 171 |
} |
| 172 |
public function get_price_text_css( $attributes, $device = '' ) { |
| 173 |
$typographyValueGlobal = ! empty( $attributes['priceTypographyGlobal'] ) ? $attributes['priceTypographyGlobal'] : array(); |
| 174 |
return array_merge( |
| 175 |
[ 'color' => Color::get_css( isset( $attributes['priceColor'] ) ? $attributes['priceColor'] : '' ) ], |
| 176 |
isset( $attributes['priceTypography'] ) ? Typography::get_css( $attributes['priceTypography'], '', $device, $typographyValueGlobal ) : [], |
| 177 |
isset( $attributes['priceTextStroke'] ) ? TextStroke::get_css( $attributes['priceTextStroke'], '', $device ) : [], |
| 178 |
isset( $attributes['priceTextShadow'] ) ? TextShadow::get_css( $attributes['priceTextShadow'], '', $device ) : [], |
| 179 |
isset( $attributes['priceAlignment'] ) ? Alignment::get_css( $attributes['priceAlignment'], 'text-align', $device ) : [], |
| 180 |
); |
| 181 |
} |
| 182 |
} |
| 183 |
|