PluginProbe
Elementor Website Builder – more than just a page builder / 3.13.3
Elementor Website Builder – more than just a page builder v3.13.3
4.3.0-beta3 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 All 452 releases
elementor / core / kits / documents / tabs / settings-layout.php

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

357 lines 11.5 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' ),
56 'type' => Controls_Manager::SLIDER,
57 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
58 'default' => [
59 'size' => '1140',
60 ],
61 'tablet_default' => [
62 'size' => $breakpoints_default_config[ $breakpoint_key_tablet ]['default_value'],
63 ],
64 'mobile_default' => [
65 'size' => $breakpoints_default_config[ $breakpoint_key_mobile ]['default_value'],
66 ],
67 'range' => [
68 'px' => [
69 'min' => 300,
70 'max' => 1500,
71 'step' => 10,
72 ],
73 ],
74 'description' => esc_html__( 'Sets the default width of the content area (Default: 1140px)', 'elementor' ),
75 'selectors' => [
76 '.elementor-section.elementor-section-boxed > .elementor-container' => 'max-width: {{SIZE}}{{UNIT}}',
77 '.e-con' => '--container-max-width: {{SIZE}}{{UNIT}}',
78 ],
79 ]
80 );
81
82 $is_container_active = Plugin::instance()->experiments->is_feature_active( 'container' );
83
84 if ( $is_container_active ) {
85 $this->add_responsive_control(
86 'container_padding',
87 [
88 'label' => esc_html__( 'Container Padding', 'elementor' ),
89 'type' => Controls_Manager::DIMENSIONS,
90 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
91 'description' => esc_html__( 'Sets the default space inside the container (Default is 10px)', 'elementor' ),
92 'selectors' => [
93 '.e-con' => '--container-default-padding-top: {{TOP}}{{UNIT}}; --container-default-padding-right: {{RIGHT}}{{UNIT}}; --container-default-padding-bottom: {{BOTTOM}}{{UNIT}}; --container-default-padding-left: {{LEFT}}{{UNIT}};',
94 ],
95 ]
96 );
97 }
98
99 $widgets_space_label = $is_container_active
100 ? esc_html__( 'Gap between elements', 'elementor' )
101 : esc_html__( 'Widgets Space', 'elementor' );
102
103 $this->add_control(
104 'space_between_widgets',
105 [
106 'label' => $widgets_space_label,
107 'type' => Controls_Manager::SLIDER,
108 'default' => [
109 'size' => 20,
110 ],
111 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
112 'range' => [
113 'px' => [
114 'min' => 0,
115 'max' => 40,
116 ],
117 ],
118 'placeholder' => [
119 'size' => 20,
120 ],
121 'description' => esc_html__( 'Sets the default space between widgets (Default: 20px)', 'elementor' ),
122 'selectors' => [
123 '.elementor-widget:not(:last-child)' => 'margin-bottom: {{SIZE}}{{UNIT}}',
124 '.elementor-element' => '--widgets-spacing: {{SIZE}}{{UNIT}}',
125 ],
126 ]
127 );
128
129 $this->add_control(
130 'page_title_selector',
131 [
132 'label' => esc_html__( 'Page Title Selector', 'elementor' ),
133 'type' => Controls_Manager::TEXT,
134 'default' => 'h1.entry-title',
135 'placeholder' => 'h1.entry-title',
136 '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' ),
137 'label_block' => true,
138 'selectors' => [
139 // Hack to convert the value into a CSS selector.
140 '' => '}{{VALUE}}{display: var(--page-title-display)',
141 ],
142 ]
143 );
144
145 $this->add_control(
146 'stretched_section_container',
147 [
148 'label' => esc_html__( 'Stretched Section Fit To', 'elementor' ),
149 'type' => Controls_Manager::TEXT,
150 'placeholder' => 'body',
151 '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' ),
152 'label_block' => true,
153 'frontend_available' => true,
154 ]
155 );
156
157 /**
158 * @var PageTemplatesModule $page_templates_module
159 */
160 $page_templates_module = Plugin::$instance->modules_manager->get_modules( 'page-templates' );
161 $page_templates = $page_templates_module->add_page_templates( [], null, null );
162
163 // Removes the Theme option from the templates because 'default' is already handled.
164 unset( $page_templates[ PageTemplatesModule::TEMPLATE_THEME ] );
165
166 $page_template_control_options = [
167 'label' => esc_html__( 'Default Page Layout', 'elementor' ),
168 'options' => [
169 // This is here because the "Theme" string is different than the default option's string.
170 'default' => esc_html__( 'Theme', 'elementor' ),
171 ] + $page_templates,
172 ];
173
174 $page_templates_module->add_template_controls( $this->parent, 'default_page_template', $page_template_control_options );
175
176 $this->end_controls_section();
177
178 $this->start_controls_section(
179 'section_breakpoints',
180 [
181 'label' => esc_html__( 'Breakpoints', 'elementor' ),
182 'tab' => $this->get_id(),
183 ]
184 );
185
186 $prefix = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX;
187 $options = [];
188
189 foreach ( $breakpoints_default_config as $breakpoint_key => $breakpoint ) {
190 $options[ $prefix . $breakpoint_key ] = $breakpoint['label'];
191 }
192
193 if ( Plugin::$instance->experiments->is_feature_active( 'additional_custom_breakpoints' ) ) {
194 $active_breakpoints_control_type = Controls_Manager::SELECT2;
195 } else {
196 $active_breakpoints_control_type = Controls_Manager::HIDDEN;
197 }
198
199 $this->add_control(
200 self::ACTIVE_BREAKPOINTS_CONTROL_ID,
201 [
202 'label' => esc_html__( 'Active Breakpoints', 'elementor' ),
203 'type' => $active_breakpoints_control_type,
204 'description' => esc_html__( 'Mobile and Tablet options cannot be deleted.', 'elementor' ),
205 'options' => $options,
206 'default' => [
207 $prefix . $breakpoint_key_mobile,
208 $prefix . $breakpoint_key_tablet,
209 ],
210 'select2options' => [
211 'allowClear' => false,
212 ],
213 'lockedOptions' => [
214 $prefix . $breakpoint_key_mobile,
215 $prefix . $breakpoint_key_tablet,
216 ],
217 'label_block' => true,
218 'render_type' => 'none',
219 'frontend_available' => true,
220 'multiple' => true,
221 ]
222 );
223
224 $this->add_breakpoints_controls();
225
226 // Include the old mobile and tablet breakpoint controls as hidden for backwards compatibility.
227 $this->add_control( 'viewport_md', [ 'type' => Controls_Manager::HIDDEN ] );
228 $this->add_control( 'viewport_lg', [ 'type' => Controls_Manager::HIDDEN ] );
229
230 $this->end_controls_section();
231 }
232
233 /**
234 * Before Save
235 *
236 * Runs Before the Kit document is saved.
237 *
238 * For backwards compatibility, when the mobile and tablet breakpoints are updated, we also update the
239 * old breakpoint settings ('viewport_md', 'viewport_lg' ) with the saved values + 1px. The reason 1px
240 * is added is because the old breakpoints system was min-width based, and the new system introduced in
241 * Elementor v3.2.0 is max-width based.
242 *
243 * @since 3.2.0
244 *
245 * @param array $data
246 * @return array $data
247 */
248 public function before_save( array $data ) {
249 // When creating a default kit, $data['settings'] is empty and should remain empty, so settings.
250 if ( empty( $data['settings'] ) ) {
251 return $data;
252 }
253
254 $prefix = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX;
255 $mobile_breakpoint_key = $prefix . Breakpoints_Manager::BREAKPOINT_KEY_MOBILE;
256 $tablet_breakpoint_key = $prefix . Breakpoints_Manager::BREAKPOINT_KEY_TABLET;
257
258 $default_breakpoint_config = Breakpoints_Manager::get_default_config();
259
260 // Update the old mobile breakpoint. If the setting is empty, use the default value.
261 $data['settings'][ $prefix . 'md' ] = empty( $data['settings'][ $mobile_breakpoint_key ] )
262 ? $default_breakpoint_config[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ]['default_value'] + 1
263 : $data['settings'][ $mobile_breakpoint_key ] + 1;
264
265 // Update the old tablet breakpoint. If the setting is empty, use the default value.
266 $data['settings'][ $prefix . 'lg' ] = empty( $data['settings'][ $tablet_breakpoint_key ] )
267 ? $default_breakpoint_config[ Breakpoints_Manager::BREAKPOINT_KEY_TABLET ]['default_value'] + 1
268 : $data['settings'][ $tablet_breakpoint_key ] + 1;
269
270 return $data;
271 }
272
273 public function on_save( $data ) {
274 if ( ! isset( $data['settings'] ) || ( isset( $data['settings']['post_status'] ) && Document::STATUS_PUBLISH !== $data['settings']['post_status'] ) ) {
275 return;
276 }
277
278 $should_compile_css = false;
279
280 $breakpoints_default_config = Breakpoints_Manager::get_default_config();
281
282 foreach ( $breakpoints_default_config as $breakpoint_key => $default_config ) {
283 $breakpoint_setting_key = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX . $breakpoint_key;
284
285 if ( isset( $data['settings'][ $breakpoint_setting_key ] ) ) {
286 $should_compile_css = true;
287 }
288 }
289
290 if ( $should_compile_css ) {
291 Breakpoints_Manager::compile_stylesheet_templates();
292 }
293 }
294
295 private function add_breakpoints_controls() {
296 $default_breakpoints_config = Breakpoints_Manager::get_default_config();
297 $prefix = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX;
298
299 // If the ACB experiment is inactive, only add the mobile and tablet controls.
300 if ( ! Plugin::$instance->experiments->is_feature_active( 'additional_custom_breakpoints' ) ) {
301 $default_breakpoints_config = array_intersect_key( $default_breakpoints_config, array_flip( [ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE, Breakpoints_Manager::BREAKPOINT_KEY_TABLET ] ) );
302 }
303
304 // Add a control for each of the **default** breakpoints.
305 foreach ( $default_breakpoints_config as $breakpoint_key => $default_breakpoint_config ) {
306 $this->add_control(
307 'breakpoint_' . $breakpoint_key . '_heading',
308 [
309 'label' => $default_breakpoint_config['label'],
310 'type' => Controls_Manager::HEADING,
311 'conditions' => [
312 'terms' => [
313 [
314 'name' => 'active_breakpoints',
315 'operator' => 'contains',
316 'value' => $prefix . $breakpoint_key,
317 ],
318 ],
319 ],
320 ]
321 );
322
323 $control_config = [
324 'label' => esc_html__( 'Breakpoint', 'elementor' ) . ' (px)',
325 'type' => Controls_Manager::NUMBER,
326 'placeholder' => $default_breakpoint_config['default_value'],
327 'frontend_available' => true,
328 'separator' => 'after',
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