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 / container / block.php

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

223 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\Container;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\BlockBaseAbstract;
9 use ABlocks\Classes\CssGenerator;
10 use ABlocks\Controls\Dimensions;
11 use ABlocks\Controls\BackgroundOverlay;
12 use ABlocks\Controls\Range;
13 use ABlocks\Helper;
14
15 class Block extends BlockBaseAbstract {
16 protected $block_name = 'container';
17
18 public function build_css( $attributes ) {
19 $css_generator = new CssGenerator( $attributes, $this->block_name );
20
21 $css_generator->add_class_styles(
22 '.ablocks-is-fse-theme {{WRAPPER}}:not(.block-editor-block-list__block).ablocks-block--container--is-root, body:not(.ablocks-is-fse-theme) {{WRAPPER}}:not(.block-editor-block-list__block).ablocks-block--container--is-root',
23 $this->reset_static_css( $attributes ),
24 $this->reset_static_css( $attributes, 'Tablet' ),
25 $this->reset_static_css( $attributes, 'Mobile' ),
26 );
27
28 $css_generator->add_class_styles(
29 '{{WRAPPER}}.ablocks-block--container',
30 $this->get_main_wrapper_css( $attributes ),
31 $this->get_main_wrapper_css( $attributes, 'Tablet' ),
32 $this->get_main_wrapper_css( $attributes, 'Mobile' )
33 );
34
35 $css_generator->add_class_styles(
36 '{{WRAPPER}} > .ablocks-block-container',
37 $this->get_block_container_css( $attributes ),
38 $this->get_block_container_css( $attributes, 'Tablet' ),
39 $this->get_block_container_css( $attributes, 'Mobile' )
40 );
41
42 $css_generator->add_class_styles(
43 '{{WRAPPER}} > .ablocks-block-container',
44 $this->get_inner_blocks_closest_parent_css( $attributes ),
45 $this->get_inner_blocks_closest_parent_css( $attributes, 'Tablet' ),
46 $this->get_inner_blocks_closest_parent_css( $attributes, 'Mobile' )
47 );
48 $css_generator->add_class_styles(
49 '{{WRAPPER}} > .ablocks-block-container > *:not(style,.ablocks-block--container)',
50 $this->get_container_inner_blocks_row_column_display_css( $attributes ),
51 $this->get_container_inner_blocks_row_column_display_css( $attributes, 'Tablet' ),
52 $this->get_container_inner_blocks_row_column_display_css( $attributes, 'Mobile' )
53 );
54
55 $css_generator->add_class_styles(
56 '{{WRAPPER}}::before',
57 $this->get_container_before_css( $attributes ),
58 $this->get_container_before_css( $attributes, 'Tablet' ),
59 $this->get_container_before_css( $attributes, 'Mobile' ),
60 );
61 $css_generator->add_class_styles(
62 '{{WRAPPER}}:hover::before',
63 $this->get_container_before_hover_css( $attributes ),
64 $this->get_container_before_hover_css( $attributes, 'Tablet' ),
65 $this->get_container_before_hover_css( $attributes, 'Mobile' ),
66 );
67
68 return $css_generator->generate_css();
69 }
70
71 public function get_inner_blocks_closest_parent_css( $attributes, $device = '' ) {
72 $css = [];
73
74 if ( ! empty( $attributes['dir'][ 'value' . $device ] ) ) {
75 $css['flex-direction'] = $attributes['dir'][ 'value' . $device ];
76 }
77 if ( ! empty( $attributes['justification'][ 'value' . $device ] ) ) {
78 $css['justify-content'] = $attributes['justification'][ 'value' . $device ];
79 }
80 if ( ! empty( $attributes['alignment'][ 'value' . $device ] ) ) {
81 $css['align-items'] = $attributes['alignment'][ 'value' . $device ];
82 }
83 if ( ! empty( $attributes['wrapping'][ 'value' . $device ] ) ) {
84 $css['flex-wrap'] = $attributes['wrapping'][ 'value' . $device ];
85 }
86 return array_merge(
87 $css,
88 Range::get_css([
89 'attributeValue' => $attributes['minimumHeight'],
90 'attributeObjectKey' => 'value',
91 'isResponsive' => true,
92 'hasUnit' => true,
93 'defaultValue' => 0,
94 'property' => 'min-height',
95 'unitDefaultValue' => 'px',
96 'device' => $device,
97 ]),
98 Range::get_css([
99 'attributeValue' => $attributes['gap'],
100 'attributeObjectKey' => 'rowGap',
101 'isResponsive' => true,
102 'hasUnit' => true,
103 'defaultValue' => 0,
104 'property' => 'row-gap',
105 'unitDefaultValue' => 'px',
106 'device' => $device,
107 ]),
108 Range::get_css([
109 'attributeValue' => $attributes['gap'],
110 'attributeObjectKey' => 'columnGap',
111 'isResponsive' => true,
112 'hasUnit' => true,
113 'defaultValue' => 0,
114 'property' => 'column-gap',
115 'unitDefaultValue' => 'px',
116 'device' => $device,
117 ]),
118 );
119
120 }
121 public function get_container_inner_blocks_row_column_display_css( $attributes, $device = '' ) {
122 $css = [];
123 if ( ! empty( $attributes['dir'][ 'value' . $device ] ) && ( 'row' === $attributes['dir'][ 'value' . $device ] || 'row-reverse' === $attributes['dir'][ 'value' . $device ] ) ) {
124 $css['display'] = 'inline-block';
125 $css['width'] = 'auto';
126 }
127 return $css;
128 }
129
130 public function get_block_container_css( $attributes, $device = '' ) {
131 $css = [];
132 $preparedContentWidth = Range::get_css([
133 'attributeValue' => $attributes['containerContentWidth'],
134 'attributeObjectKey' => 'value',
135 'isResponsive' => true,
136 'hasUnit' => true,
137 'defaultValue' => 1140,
138 'property' => 'value',
139 'unitDefaultValue' => 'px',
140 'device' => $device,
141 ]);
142 $content_box_width_value = $preparedContentWidth['value'] ?? '';
143 if ( empty( $content_box_width_value ) && $device === '' ) {
144 $content_box_width_value = Helper::get_settings( 'default_container_width' ) ?? 1140;
145 }
146 $content_box_width_unit = $preparedContentWidth['valueUnit'] ?? 'px';
147 $is_root_container = isset( $attributes['isRootContainer'] ) ? $attributes['isRootContainer'] : false;
148
149 if ( $is_root_container && $attributes['containerWidthType'] === 'boxed' && ! empty( $content_box_width_value ) ) {
150 $css['max-width'] = "min(100%, {$content_box_width_value}{$content_box_width_unit})";
151 $css['margin-right'] = 'auto !important';
152 $css['margin-left'] = 'auto !important';
153 }
154
155 return $css;
156 }
157
158 public function reset_static_css( $attributes, $device = '' ) {
159 $preparedContainer = Range::get_css([
160 'attributeValue' => $attributes['containerWidth'],
161 'attributeObjectKey' => 'value',
162 'isResponsive' => true,
163 'hasUnit' => true,
164 'defaultValue' => 100,
165 'property' => 'value',
166 'unitDefaultValue' => '%',
167 'device' => '',
168 ]);
169 $css = [];
170 if ( 'custom' === $attributes['containerWidthType'] && ! empty( $preparedContainer['value'] ) ) {
171 $css['margin-left'] = 'auto !important';
172 $css['margin-right'] = 'auto !important';
173 }
174 return $css;
175 }
176 public function get_main_wrapper_css( $attributes, $device = '' ) {
177 $css = [];
178 $prepared_container = Range::get_css([
179 'attributeValue' => $attributes['containerWidth'],
180 'attributeObjectKey' => 'value',
181 'isResponsive' => true,
182 'hasUnit' => true,
183 'defaultValue' => 100,
184 'property' => 'value',
185 'unitDefaultValue' => '%',
186 'device' => $device,
187 ]);
188
189 $is_root_container = isset( $attributes['isRootContainer'] ) ? $attributes['isRootContainer'] : false;
190 if ( ( ! $is_root_container || 'custom' === $attributes['containerWidthType'] ) && ! empty( $prepared_container['value'] ) ) {
191 $css['max-width'] = "min(100%, {$prepared_container['value']}{$prepared_container['valueUnit']}) !important";
192 }
193
194 if ( 'custom' === $attributes['containerWidthType'] && ! empty( $prepared_container['value'] ) && $is_root_container ) {
195 $css['margin-left'] = 'auto !important';
196 $css['margin-right'] = 'auto !important';
197 }
198
199 if ( $is_root_container && 'custom' !== $attributes['containerWidthType'] ) {
200 unset( $css['max-width'] );
201 unset( $css['margin-left'] );
202 unset( $css['margin-right'] );
203 }
204
205 $css['overflow'] = ! empty( $attributes['overflow'] ) ? $attributes['overflow'] : 'visible';
206
207 return array_merge(
208 Dimensions::get_css( $attributes['_padding'], 'padding', $device ),
209 $css
210 );
211 }
212 public static function get_container_before_css( $attributes, $device = '' ) {
213 return array_merge(
214 BackgroundOverlay::get_before_css( $attributes['_backgroundOverlay'], $attributes['_border'], 'background', $device ),
215 );
216 }
217 public static function get_container_before_hover_css( $attributes, $device = '' ) {
218 return array_merge(
219 BackgroundOverlay::get_before_hover_css( $attributes['_backgroundOverlay'], $attributes['_border'], 'background', $device ),
220 );
221 }
222 }
223