PluginProbe
Elementor Website Builder – more than just a page builder / 3.7.3
Elementor Website Builder – more than just a page builder v3.7.3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / kits / documents / tabs / settings-layout.php

settings-layout.php in Elementor Website Builder – more than just a page builder 3.7.3, at core/kits/documents/tabs/settings-layout.php

357 lines 11.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Kits\Documents\Tabs;
3
4 use Elementor\Core\Breakpoints\Breakpoint;
5 use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
6 use Elementor\Plugin;
7 use Elementor\Controls_Manager;
8 use Elementor\Core\Base\Document;
9 use Elementor\Modules\PageTemplates\Module as PageTemplatesModule;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15 class Settings_Layout extends Tab_Base {
16
17 const ACTIVE_BREAKPOINTS_CONTROL_ID = 'active_breakpoints';
18
19 public function get_id() {
20 return 'settings-layout';
21 }
22
23 public function get_title() {
24 return esc_html__( 'Layout', 'elementor' );
25 }
26
27 public function get_group() {
28 return 'settings';
29 }
30
31 public function get_icon() {
32 return 'eicon-layout-settings';
33 }
34
35 public function get_help_url() {
36 return 'https://go.elementor.com/global-layout/';
37 }
38
39 protected function register_tab_controls() {
40 $breakpoints_default_config = Breakpoints_Manager::get_default_config();
41 $breakpoint_key_mobile = Breakpoints_Manager::BREAKPOINT_KEY_MOBILE;
42 $breakpoint_key_tablet = Breakpoints_Manager::BREAKPOINT_KEY_TABLET;
43
44 $this->start_controls_section(
45 'section_' . $this->get_id(),
46 [
47 'label' => esc_html__( 'Layout Settings', 'elementor' ),
48 'tab' => $this->get_id(),
49 ]
50 );
51
52 $this->add_responsive_control(
53 'container_width',
54 [
55 'label' => esc_html__( 'Content Width', 'elementor' ) . ' (px)',
56 'type' => Controls_Manager::SLIDER,
57 'default' => [
58 'size' => '1140',
59 ],
60 'tablet_default' => [
61 'size' => $breakpoints_default_config[ $breakpoint_key_tablet ]['default_value'],
62 ],
63 'mobile_default' => [
64 'size' => $breakpoints_default_config[ $breakpoint_key_mobile ]['default_value'],
65 ],
66 'range' => [
67 'px' => [
68 'min' => 300,
69 'max' => 1500,
70 'step' => 10,
71 ],
72 ],
73 'description' => esc_html__( 'Sets the default width of the content area (Default: 1140)', 'elementor' ),
74 'selectors' => [
75 '.elementor-section.elementor-section-boxed > .elementor-container' => 'max-width: {{SIZE}}{{UNIT}}',
76 '.e-container' => '--container-max-width: {{SIZE}}{{UNIT}}',
77 ],
78 ]
79 );
80
81 $is_container_active = Plugin::instance()->experiments->is_feature_active( 'container' );
82
83 if ( $is_container_active ) {
84 $this->add_responsive_control(
85 'container_padding',
86 [
87 'label' => esc_html__( 'Container Padding', 'elementor' ),
88 'type' => Controls_Manager::DIMENSIONS,
89 'size_units' => [ 'px', 'em', '%', 'rem' ],
90 'default' => [
91 'unit' => 'px',
92 ],
93 'description' => esc_html__( 'Sets the default space inside the container (Default is 10px)', 'elementor' ),
94 'selectors' => [
95 '.e-container' => '--container-default-padding-top: {{TOP}}{{UNIT}}; --container-default-padding-right: {{RIGHT}}{{UNIT}}; --container-default-padding-bottom: {{BOTTOM}}{{UNIT}}; --container-default-padding-left: {{LEFT}}{{UNIT}};',
96 ],
97 ]
98 );
99 }
100
101 $widgets_space_label = $is_container_active
102 ? esc_html__( 'Gap between elements', 'elementor' )
103 : esc_html__( 'Widgets Space', 'elementor' );
104
105 $this->add_control(
106 'space_between_widgets',
107 [
108 'label' => $widgets_space_label . ' (px)',
109 'type' => Controls_Manager::SLIDER,
110 'default' => [
111 'size' => 20,
112 ],
113 'range' => [
114 'px' => [
115 'min' => 0,
116 'max' => 40,
117 ],
118 ],
119 'placeholder' => [
120 'size' => '20',
121 ],
122 'description' => esc_html__( 'Sets the default space between widgets (Default: 20)', 'elementor' ),
123 'selectors' => [
124 '.elementor-widget:not(:last-child)' => 'margin-bottom: {{SIZE}}{{UNIT}}',
125 '.elementor-element' => '--widgets-spacing: {{SIZE}}{{UNIT}}',
126 ],
127 ]
128 );
129
130 $this->add_control(
131 'page_title_selector',
132 [
133 'label' => esc_html__( 'Page Title Selector', 'elementor' ),
134 'type' => Controls_Manager::TEXT,
135 'default' => 'h1.entry-title',
136 'placeholder' => 'h1.entry-title',
137 'description' => esc_html__( 'Elementor lets you hide the page title. This works for themes that have "h1.entry-title" selector. If your theme\'s selector is different, please enter it above.', 'elementor' ),
138 'label_block' => true,
139 'selectors' => [
140 // Hack to convert the value into a CSS selector.
141 '' => '}{{VALUE}}{display: var(--page-title-display)',
142 ],
143 ]
144 );
145
146 $this->add_control(
147 'stretched_section_container',
148 [
149 'label' => esc_html__( 'Stretched Section Fit To', 'elementor' ),
150 'type' => Controls_Manager::TEXT,
151 'placeholder' => 'body',
152 'description' => esc_html__( 'Enter parent element selector to which stretched sections will fit to (e.g. #primary / .wrapper / main etc). Leave blank to fit to page width.', 'elementor' ),
153 'label_block' => true,
154 'frontend_available' => true,
155 ]
156 );
157
158 /**
159 * @var PageTemplatesModule $page_templates_module
160 */
161 $page_templates_module = Plugin::$instance->modules_manager->get_modules( 'page-templates' );
162 $page_templates = $page_templates_module->add_page_templates( [], null, null );
163
164 // Removes the Theme option from the templates because 'default' is already handled.
165 unset( $page_templates[ PageTemplatesModule::TEMPLATE_THEME ] );
166
167 $page_template_control_options = [
168 'label' => esc_html__( 'Default Page Layout', 'elementor' ),
169 'options' => [
170 // This is here because the "Theme" string is different than the default option's string.
171 'default' => esc_html__( 'Theme', 'elementor' ),
172 ] + $page_templates,
173 ];
174
175 $page_templates_module->add_template_controls( $this->parent, 'default_page_template', $page_template_control_options );
176
177 $this->end_controls_section();
178
179 $this->start_controls_section(
180 'section_breakpoints',
181 [
182 'label' => esc_html__( 'Breakpoints', 'elementor' ),
183 'tab' => $this->get_id(),
184 ]
185 );
186
187 $prefix = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX;
188 $options = [];
189
190 foreach ( $breakpoints_default_config as $breakpoint_key => $breakpoint ) {
191 $options[ $prefix . $breakpoint_key ] = $breakpoint['label'];
192 }
193
194 if ( Plugin::$instance->experiments->is_feature_active( 'additional_custom_breakpoints' ) ) {
195 $active_breakpoints_control_type = Controls_Manager::SELECT2;
196 } else {
197 $active_breakpoints_control_type = Controls_Manager::HIDDEN;
198 }
199
200 $this->add_control(
201 self::ACTIVE_BREAKPOINTS_CONTROL_ID,
202 [
203 'label' => esc_html__( 'Active Breakpoints', 'elementor' ),
204 'type' => $active_breakpoints_control_type,
205 'description' => esc_html__( 'Mobile and Tablet options cannot be deleted.', 'elementor' ),
206 'options' => $options,
207 'default' => [
208 $prefix . $breakpoint_key_mobile,
209 $prefix . $breakpoint_key_tablet,
210 ],
211 'select2options' => [
212 'allowClear' => false,
213 ],
214 'lockedOptions' => [
215 $prefix . $breakpoint_key_mobile,
216 $prefix . $breakpoint_key_tablet,
217 ],
218 'label_block' => true,
219 'render_type' => 'none',
220 'frontend_available' => true,
221 'multiple' => true,
222 ]
223 );
224
225 $this->add_breakpoints_controls();
226
227 // Include the old mobile and tablet breakpoint controls as hidden for backwards compatibility.
228 $this->add_control( 'viewport_md', [ 'type' => Controls_Manager::HIDDEN ] );
229 $this->add_control( 'viewport_lg', [ 'type' => Controls_Manager::HIDDEN ] );
230
231 $this->end_controls_section();
232 }
233
234 /**
235 * Before Save
236 *
237 * Runs Before the Kit document is saved.
238 *
239 * For backwards compatibility, when the mobile and tablet breakpoints are updated, we also update the
240 * old breakpoint settings ('viewport_md', 'viewport_lg' ) with the saved values + 1px. The reason 1px
241 * is added is because the old breakpoints system was min-width based, and the new system introduced in
242 * Elementor v3.2.0 is max-width based.
243 *
244 * @since 3.2.0
245 *
246 * @param array $data
247 * @return array $data
248 */
249 public function before_save( array $data ) {
250 // When creating a default kit, $data['settings'] is empty and should remain empty, so settings.
251 if ( empty( $data['settings'] ) ) {
252 return $data;
253 }
254
255 $prefix = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX;
256 $mobile_breakpoint_key = $prefix . Breakpoints_Manager::BREAKPOINT_KEY_MOBILE;
257 $tablet_breakpoint_key = $prefix . Breakpoints_Manager::BREAKPOINT_KEY_TABLET;
258
259 $default_breakpoint_config = Breakpoints_Manager::get_default_config();
260
261 // Update the old mobile breakpoint. If the setting is empty, use the default value.
262 $data['settings'][ $prefix . 'md' ] = empty( $data['settings'][ $mobile_breakpoint_key ] )
263 ? $default_breakpoint_config[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ]['default_value'] + 1
264 : $data['settings'][ $mobile_breakpoint_key ] + 1;
265
266 // Update the old tablet breakpoint. If the setting is empty, use the default value.
267 $data['settings'][ $prefix . 'lg' ] = empty( $data['settings'][ $tablet_breakpoint_key ] )
268 ? $default_breakpoint_config[ Breakpoints_Manager::BREAKPOINT_KEY_TABLET ]['default_value'] + 1
269 : $data['settings'][ $tablet_breakpoint_key ] + 1;
270
271 return $data;
272 }
273
274 public function on_save( $data ) {
275 if ( ! isset( $data['settings'] ) || ( isset( $data['settings']['post_status'] ) && Document::STATUS_PUBLISH !== $data['settings']['post_status'] ) ) {
276 return;
277 }
278
279 $should_compile_css = false;
280
281 $breakpoints_default_config = Breakpoints_Manager::get_default_config();
282
283 foreach ( $breakpoints_default_config as $breakpoint_key => $default_config ) {
284 $breakpoint_setting_key = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX . $breakpoint_key;
285
286 if ( isset( $data['settings'][ $breakpoint_setting_key ] ) ) {
287 $should_compile_css = true;
288 }
289 }
290
291 if ( $should_compile_css ) {
292 Breakpoints_Manager::compile_stylesheet_templates();
293 }
294 }
295
296 private function add_breakpoints_controls() {
297 $default_breakpoints_config = Breakpoints_Manager::get_default_config();
298 $prefix = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX;
299
300 // If the ACB experiment is inactive, only add the mobile and tablet controls.
301 if ( ! Plugin::$instance->experiments->is_feature_active( 'additional_custom_breakpoints' ) ) {
302 $default_breakpoints_config = array_intersect_key( $default_breakpoints_config, array_flip( [ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE, Breakpoints_Manager::BREAKPOINT_KEY_TABLET ] ) );
303 }
304
305 // Add a control for each of the **default** breakpoints.
306 foreach ( $default_breakpoints_config as $breakpoint_key => $default_breakpoint_config ) {
307 $this->add_control(
308 'breakpoint_' . $breakpoint_key . '_heading',
309 [
310 'label' => $default_breakpoint_config['label'],
311 'type' => Controls_Manager::HEADING,
312 'conditions' => [
313 'terms' => [
314 [
315 'name' => 'active_breakpoints',
316 'operator' => 'contains',
317 'value' => $prefix . $breakpoint_key,
318 ],
319 ],
320 ],
321 ]
322 );
323
324 $control_config = [
325 'label' => esc_html__( 'Breakpoint', 'elementor' ) . ' (px)',
326 'type' => Controls_Manager::NUMBER,
327 'placeholder' => $default_breakpoint_config['default_value'],
328 'frontend_available' => true,
329 'validators' => [
330 'Breakpoint' => [
331 'breakpointName' => $breakpoint_key,
332 ],
333 ],
334 'conditions' => [
335 'terms' => [
336 [
337 'name' => 'active_breakpoints',
338 'operator' => 'contains',
339 'value' => $prefix . $breakpoint_key,
340 ],
341 ],
342 ],
343 ];
344
345 if ( Breakpoints_Manager::BREAKPOINT_KEY_WIDESCREEN === $breakpoint_key ) {
346 $control_config['description'] = esc_html__(
347 'Widescreen breakpoint settings will apply from the selected value and up.',
348 'elementor'
349 );
350 }
351
352 // Add the breakpoint Control itself.
353 $this->add_control( $prefix . $breakpoint_key, $control_config );
354 }
355 }
356 }
357