PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.1
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 1.1.2 All 80 releases
ablocks / includes / blocks / price-menu / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.1, at includes/blocks/price-menu/block.php

302 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\PriceMenu;
3
4 use ABlocks\Classes\BlockBaseAbstract;
5 use ABlocks\Classes\CssGenerator;
6 use ABlocks\Controls\Alignment;
7 use ABlocks\Controls\Border;
8 use ABlocks\Controls\Dimensions;
9 use ABlocks\Controls\Typography;
10 use ABlocks\Controls\TextShadow;
11 use ABlocks\Controls\TextStroke;
12 use ABlocks\Controls\Range;
13
14 class Block extends BlockBaseAbstract {
15 protected $block_name = 'price-menu';
16
17 public function build_css( $attributes ) {
18
19 $css_generator = new CssGenerator( $attributes, $this->block_name );
20
21 $css_generator->add_class_styles(
22 '{{WRAPPER}} .ablocks-block-container',
23 $this->get_all_menu_css( $attributes, '' ),
24 $this->get_all_menu_css( $attributes, 'Tablet' ),
25 $this->get_all_menu_css( $attributes, 'Mobile' ),
26 );
27 $css_generator->add_class_styles(
28 '{{WRAPPER}} .ablocks-price-menu-item, {{WRAPPER}} .ablocks-price-menu-item-details',
29 $this->get_gap_around_css( $attributes, '' ),
30 $this->get_gap_around_css( $attributes, 'Tablet' ),
31 $this->get_gap_around_css( $attributes, 'Mobile' ),
32 );
33 $css_generator->add_class_styles(
34 '{{WRAPPER}} .ablocks-price-menu-item-details-brief',
35 $this->get_details_brief_css( $attributes, '' ),
36 $this->get_details_brief_css( $attributes, 'Tablet' ),
37 $this->get_details_brief_css( $attributes, 'Mobile' ),
38 );
39 $css_generator->add_class_styles(
40 '{{WRAPPER}} .ablocks-block--price-menu-item',
41 $this->get_item_css( $attributes, '' ),
42 $this->get_item_css( $attributes, 'Tablet' ),
43 $this->get_item_css( $attributes, 'Mobile' ),
44 );
45 $css_generator->add_class_styles(
46 '{{WRAPPER}} .ablocks-block--price-menu-item:hover',
47 $this->get_item_hover_css( $attributes, '' ),
48 $this->get_item_hover_css( $attributes, 'Tablet' ),
49 $this->get_item_hover_css( $attributes, 'Mobile' ),
50 );
51
52 $css_generator->add_class_styles(
53 '{{WRAPPER}} .ablocks-price-menu-item',
54 $this->get_inner_item_css( $attributes, '' ),
55 $this->get_inner_item_css( $attributes, 'Tablet' ),
56 $this->get_inner_item_css( $attributes, 'Mobile' ),
57 );
58
59 // TitleText CSS
60 $css_generator->add_class_styles(
61 '{{WRAPPER}} .ablocks-price-menu-item-details-title',
62 $this->get_title_text_css( $attributes, '' ),
63 $this->get_title_text_css( $attributes, 'Tablet' ),
64 $this->get_title_text_css( $attributes, 'Mobile' ),
65 );
66 // DescriptionText CSS
67 $css_generator->add_class_styles(
68 '{{WRAPPER}} .ablocks-price-menu-item-details-des',
69 $this->get_description_text_css( $attributes, '' ),
70 $this->get_description_text_css( $attributes, 'Tablet' ),
71 $this->get_description_text_css( $attributes, 'Mobile' ),
72 );
73 // SeparatorText CSS
74 $css_generator->add_class_styles(
75 '{{WRAPPER}} .ablocks-price-menu-divider__pattern-' . ( $attributes['dividerType'] === 'mask-style' ? 'mask' : 'css' ),
76 $this->get_divider_css( $attributes, '' ),
77 $this->get_divider_css( $attributes, 'Tablet' ),
78 $this->get_divider_css( $attributes, 'Mobile' ),
79 );
80 // PriceText CSS
81 $css_generator->add_class_styles(
82 '{{WRAPPER}} .ablocks-price-menu-item-price',
83 $this->get_price_text_css( $attributes, '' ),
84 $this->get_price_text_css( $attributes, 'Tablet' ),
85 $this->get_price_text_css( $attributes, 'Mobile' ),
86 );
87
88 return $css_generator->generate_css();
89 }
90
91 public function get_item_css( $attributes, $device = '' ) {
92 $css = [];
93
94 if ( isset( $attributes['transition'] ) ) {
95 $css['transition-duration'] = $attributes['transition'] . 's';
96 }
97
98 if ( isset( $attributes['itemBackground'] ) ) {
99 $css['background'] = $attributes['itemBackground'];
100 }
101 return array_merge(
102 $css,
103 isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'justify-content', $device ) : [],
104 isset( $attributes['itemBorder'] ) ? Border::get_css( $attributes['itemBorder'], '', $device ) : [],
105 isset( $attributes['itemPadding'] ) ? Dimensions::get_css( $attributes['itemPadding'], 'padding', $device ) : [],
106 );
107 }
108
109 public function get_item_hover_css( $attributes, $device = '' ) {
110 $css = [];
111 if ( isset( $attributes['itemBackgroundH'] ) ) {
112 $css['background'] = $attributes['itemBackgroundH'];
113 }
114 return array_merge(
115 $css,
116 isset( $attributes['itemBorder'] ) ? Border::get_hover_css( $attributes['itemBorder'], '', $device ) : [],
117 );
118 }
119
120 public function get_inner_item_css( $attributes, $device = '' ) {
121 $css = [];
122
123 if ( isset( $attributes['itemsDirection'][ 'value' . $device ] ) ) {
124 $css['flex-direction'] = $attributes['itemsDirection'][ 'value' . $device ];
125 }
126
127 if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) {
128 $css['align-items'] = $attributes['alignment'][ 'value' . $device ];
129 }
130
131 return $css;
132 }
133
134 public function get_gap_around_css( $attributes, $device = '' ) {
135 $css = [];
136 if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) {
137 $css['align-items'] = $attributes['alignment'][ 'value' . $device ];
138 }
139
140 return array_merge(
141 $css,
142 Range::get_css([
143 'attributeValue' => $attributes['gap'],
144 'attribute_object_key' => 'value',
145 'isResponsive' => true,
146 'hasUnit' => true,
147 'defaultValue' => 10,
148 'unitDefaultValue' => 'px',
149 'property' => 'gap',
150 'device' => $device,
151 ]),
152 );
153 }
154
155 public function get_details_brief_css( $attributes, $device = '' ) {
156 $css = [];
157 if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) {
158 if ( $attributes['itemsDirection'][ 'value' . $device ] === 'row' ) {
159 $css['justify-content'] = 'space-between';
160 } else {
161 $css['justify-content'] = $attributes['alignment'][ 'value' . $device ];
162 }
163 }
164
165 return array_merge(
166 Range::get_css([
167 'attributeValue' => $attributes['gap'],
168 'attribute_object_key' => 'value',
169 'isResponsive' => true,
170 'hasUnit' => true,
171 'defaultValue' => 10,
172 'unitDefaultValue' => 'px',
173 'property' => 'gap',
174 'device' => $device,
175 ]),
176 $css
177 );
178 }
179
180 public function get_all_menu_css( $attributes, $device = '' ) {
181
182 return array_merge(
183 Range::get_css([
184 'attributeValue' => $attributes['columnGap'],
185 'attribute_object_key' => 'value',
186 'isResponsive' => true,
187 'isResponsive' => true,
188 'defaultValue' => 20,
189 'unitDefaultValue' => 'px',
190 'property' => 'gap',
191 'device' => $device,
192 ]),
193 );
194 }
195
196 public function get_title_text_css( $attributes, $device = '' ) {
197 $css = [];
198 $title_color = isset( $attributes['titleColor'] ) ? $attributes['titleColor'] : '';
199
200 if ( isset( $attributes['titleColor'] ) ) {
201 $css['color'] = $title_color;
202 }
203
204 return array_merge(
205 $css,
206 isset( $attributes['titleTypography'] ) ? Typography::get_css( $attributes['titleTypography'], '', $device ) : [],
207 isset( $attributes['titleTextStroke'] ) ? TextStroke::get_css( $attributes['titleTextStroke'], '', $device ) : [],
208 isset( $attributes['titleTextShadow'] ) ? TextShadow::get_css( $attributes['titleTextShadow'], '', $device ) : [],
209 isset( $attributes['titleAlignment'] ) ? Alignment::get_css( $attributes['titleAlignment'], 'text-align', $device ) : [],
210 );
211 }
212 public function get_description_text_css( $attributes, $device = '' ) {
213 $css = [];
214 $description_color = isset( $attributes['descriptionColor'] ) ? $attributes['descriptionColor'] : '';
215
216 if ( isset( $attributes['descriptionColor'] ) && isset( $attributes['descriptionColor'] ) ) {
217 $css['color'] = $description_color;
218 }
219
220 return array_merge(
221 $css,
222 isset( $attributes['descriptionTypography'] ) ? Typography::get_css( $attributes['descriptionTypography'], '', $device ) : [],
223 isset( $attributes['descriptionTextStroke'] ) ? TextStroke::get_css( $attributes['descriptionTextStroke'], '', $device ) : [],
224 isset( $attributes['descriptionTextShadow'] ) ? TextShadow::get_css( $attributes['descriptionTextShadow'], '', $device ) : [],
225 isset( $attributes['descriptionAlignment'] ) ? Alignment::get_css( $attributes['descriptionAlignment'], 'text-align', $device ) : [],
226 );
227 }
228 public function get_divider_css( $attributes, $device = '' ) {
229 $css = [];
230 $divider_width = isset( $attributes['width'][ 'value' . $device ] ) ? $attributes['width'][ 'value' . $device ] : 60;
231 $divider_color = isset( $attributes['color'] ) ? $attributes['color'] : '#000000';
232 $default_Unit = $attributes['allowDescription'] === true ? '%' : 'px';
233
234 if ( isset( $attributes['color'] ) && ! empty( $attributes['color'] ) ) {
235 $css['--ablocks-divider-pattern-color'] = $divider_color;
236 }
237
238 $moreRangeCSS = [];
239 if ( isset( $attributes['dividerType'] ) && $attributes['dividerType'] === 'mask-style' && isset( $attributes['size'] ) && ! empty( $attributes['size'] ) ) {
240 $moreRangeCSS = Range::get_css([
241 'attributeValue' => $attributes['size'],
242 'attribute_object_key' => 'value',
243 'isResponsive' => false,
244 'defaultValue' => 20,
245 'hasUnit' => false,
246 'unitDefaultValue' => 'px',
247 'property' => '--ablocks-divider-pattern-height',
248 ]);
249 } elseif ( isset( $attributes['weight'] ) && ! empty( $attributes['weight'] ) ) {
250 $moreRangeCSS = Range::get_css([
251 'attributeValue' => $attributes['weight'],
252 'attribute_object_key' => 'value',
253 'isResponsive' => false,
254 'defaultValue' => 2,
255 'hasUnit' => false,
256 'unitDefaultValue' => 'px',
257 'property' => '--ablocks-divider-pattern-weight',
258 ]);
259 }//end if
260
261 if ( ! empty( $attributes['dividerPatternUrl'] ) ) {
262 if ( $attributes['dividerType'] === 'mask-style' ) {
263 $css['--ablocks-divider-pattern-url'] = 'url(' . $attributes['dividerPatternUrl'] . ')';
264 } else {
265 $css['--ablocks-divider-pattern-style'] = $attributes['dividerPatternUrl'];
266 }
267 }
268
269 return array_merge(
270 $css,
271 Range::get_css([
272 'attributeValue' => $attributes['width'],
273 'attribute_object_key' => 'value',
274 'isResponsive' => true,
275 'defaultValue' => 100,
276 'hasUnit' => false,
277 'unitDefaultValue' => $attributes['allowDescription'] === true ? '%' : 'px',
278 'property' => 'width',
279 'device' => $device,
280 ]),
281 $moreRangeCSS,
282 );
283 }
284 public function get_price_text_css( $attributes, $device = '' ) {
285 $css = [];
286 $price_color = isset( $attributes['priceColor'] ) ? $attributes['priceColor'] : '';
287
288 if ( isset( $attributes['priceColor'] ) ) {
289 $css['color'] = $price_color;
290 }
291
292 return array_merge(
293 $css,
294 isset( $attributes['priceTypography'] ) ? Typography::get_css( $attributes['priceTypography'], '', $device ) : [],
295 isset( $attributes['priceTextStroke'] ) ? TextStroke::get_css( $attributes['priceTextStroke'], '', $device ) : [],
296 isset( $attributes['priceTextShadow'] ) ? TextShadow::get_css( $attributes['priceTextShadow'], '', $device ) : [],
297 isset( $attributes['priceAlignment'] ) ? Alignment::get_css( $attributes['priceAlignment'], 'text-align', $device ) : [],
298 );
299 }
300
301 }
302