PluginProbe
Elementor Website Builder – more than just a page builder / 3.22.3
Elementor Website Builder – more than just a page builder v3.22.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.22.3, at core/kits/documents/tabs/settings-layout.php

373 lines 11.9 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__( 'Gaps', '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::GAPS,
108 'default' => [
109 'row' => '20',
110 'column' => '20',
111 'unit' => 'px',
112 ],
113 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
114 'placeholder' => [
115 'row' => '20',
116 'column' => '20',
117 ],
118 'description' => esc_html__( 'Sets the default space between widgets (Default: 20px)', 'elementor' ),
119 'selectors' => [
120 '.elementor-widget:not(:last-child)' => 'margin-block-end: {{ROW}}{{UNIT}}',
121 '.elementor-element' => '--widgets-spacing: {{ROW}}{{UNIT}} {{COLUMN}}{{UNIT}}',
122 ],
123 'conversion_map' => [
124 'old_key' => 'size',
125 'new_key' => 'column',
126 ],
127 'upgrade_conversion_map' => [
128 'old_key' => 'size',
129 'new_keys' => [ 'column', 'row' ],
130 ],
131 'validators' => [
132 'Number' => [
133 'min' => 0,
134 ],
135 ],
136 ]
137 );
138
139 $this->add_control(
140 'page_title_selector',
141 [
142 'label' => esc_html__( 'Page Title Selector', 'elementor' ),
143 'type' => Controls_Manager::TEXT,
144 'default' => 'h1.entry-title',
145 'placeholder' => 'h1.entry-title',
146 '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' ),
147 'label_block' => true,
148 'ai' => [
149 'active' => false,
150 ],
151 'selectors' => [
152 // Hack to convert the value into a CSS selector.
153 '' => '}{{VALUE}}{display: var(--page-title-display)',
154 ],
155 ]
156 );
157
158 $this->add_control(
159 'stretched_section_container',
160 [
161 'label' => esc_html__( 'Stretched Section Fit To', 'elementor' ),
162 'type' => Controls_Manager::TEXT,
163 'placeholder' => 'body',
164 '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' ),
165 'label_block' => true,
166 'frontend_available' => true,
167 'ai' => [
168 'active' => false,
169 ],
170 ]
171 );
172
173 /**
174 * @var PageTemplatesModule $page_templates_module
175 */
176 $page_templates_module = Plugin::$instance->modules_manager->get_modules( 'page-templates' );
177 $page_templates = $page_templates_module->add_page_templates( [], null, null );
178
179 // Removes the Theme option from the templates because 'default' is already handled.
180 unset( $page_templates[ PageTemplatesModule::TEMPLATE_THEME ] );
181
182 $page_template_control_options = [
183 'label' => esc_html__( 'Default Page Layout', 'elementor' ),
184 'options' => [
185 // This is here because the "Theme" string is different than the default option's string.
186 'default' => esc_html__( 'Theme', 'elementor' ),
187 ] + $page_templates,
188 ];
189
190 $page_templates_module->add_template_controls( $this->parent, 'default_page_template', $page_template_control_options );
191
192 $this->end_controls_section();
193
194 $this->start_controls_section(
195 'section_breakpoints',
196 [
197 'label' => esc_html__( 'Breakpoints', 'elementor' ),
198 'tab' => $this->get_id(),
199 ]
200 );
201
202 $prefix = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX;
203 $options = [];
204
205 foreach ( $breakpoints_default_config as $breakpoint_key => $breakpoint ) {
206 $options[ $prefix . $breakpoint_key ] = $breakpoint['label'];
207 }
208
209 if ( Plugin::$instance->experiments->is_feature_active( 'additional_custom_breakpoints' ) ) {
210 $active_breakpoints_control_type = Controls_Manager::SELECT2;
211 } else {
212 $active_breakpoints_control_type = Controls_Manager::HIDDEN;
213 }
214
215 $this->add_control(
216 self::ACTIVE_BREAKPOINTS_CONTROL_ID,
217 [
218 'label' => esc_html__( 'Active Breakpoints', 'elementor' ),
219 'type' => $active_breakpoints_control_type,
220 'description' => esc_html__( 'Mobile and Tablet options cannot be deleted.', 'elementor' ),
221 'options' => $options,
222 'default' => [
223 $prefix . $breakpoint_key_mobile,
224 $prefix . $breakpoint_key_tablet,
225 ],
226 'select2options' => [
227 'allowClear' => false,
228 ],
229 'lockedOptions' => [
230 $prefix . $breakpoint_key_mobile,
231 $prefix . $breakpoint_key_tablet,
232 ],
233 'label_block' => true,
234 'render_type' => 'none',
235 'frontend_available' => true,
236 'multiple' => true,
237 ]
238 );
239
240 $this->add_breakpoints_controls();
241
242 // Include the old mobile and tablet breakpoint controls as hidden for backwards compatibility.
243 $this->add_control( 'viewport_md', [ 'type' => Controls_Manager::HIDDEN ] );
244 $this->add_control( 'viewport_lg', [ 'type' => Controls_Manager::HIDDEN ] );
245
246 $this->end_controls_section();
247 }
248
249 /**
250 * Before Save
251 *
252 * Runs Before the Kit document is saved.
253 *
254 * For backwards compatibility, when the mobile and tablet breakpoints are updated, we also update the
255 * old breakpoint settings ('viewport_md', 'viewport_lg' ) with the saved values + 1px. The reason 1px
256 * is added is because the old breakpoints system was min-width based, and the new system introduced in
257 * Elementor v3.2.0 is max-width based.
258 *
259 * @since 3.2.0
260 *
261 * @param array $data
262 * @return array $data
263 */
264 public function before_save( array $data ) {
265 // When creating a default kit, $data['settings'] is empty and should remain empty, so settings.
266 if ( empty( $data['settings'] ) ) {
267 return $data;
268 }
269
270 $prefix = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX;
271 $mobile_breakpoint_key = $prefix . Breakpoints_Manager::BREAKPOINT_KEY_MOBILE;
272 $tablet_breakpoint_key = $prefix . Breakpoints_Manager::BREAKPOINT_KEY_TABLET;
273
274 $default_breakpoint_config = Breakpoints_Manager::get_default_config();
275
276 // Update the old mobile breakpoint. If the setting is empty, use the default value.
277 $data['settings'][ $prefix . 'md' ] = empty( $data['settings'][ $mobile_breakpoint_key ] )
278 ? $default_breakpoint_config[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ]['default_value'] + 1
279 : $data['settings'][ $mobile_breakpoint_key ] + 1;
280
281 // Update the old tablet breakpoint. If the setting is empty, use the default value.
282 $data['settings'][ $prefix . 'lg' ] = empty( $data['settings'][ $tablet_breakpoint_key ] )
283 ? $default_breakpoint_config[ Breakpoints_Manager::BREAKPOINT_KEY_TABLET ]['default_value'] + 1
284 : $data['settings'][ $tablet_breakpoint_key ] + 1;
285
286 return $data;
287 }
288
289 public function on_save( $data ) {
290 if ( ! isset( $data['settings'] ) || ( isset( $data['settings']['post_status'] ) && Document::STATUS_PUBLISH !== $data['settings']['post_status'] ) ) {
291 return;
292 }
293
294 $should_compile_css = false;
295
296 $breakpoints_default_config = Breakpoints_Manager::get_default_config();
297
298 foreach ( $breakpoints_default_config as $breakpoint_key => $default_config ) {
299 $breakpoint_setting_key = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX . $breakpoint_key;
300
301 if ( isset( $data['settings'][ $breakpoint_setting_key ] ) ) {
302 $should_compile_css = true;
303 }
304 }
305
306 if ( $should_compile_css ) {
307 Breakpoints_Manager::compile_stylesheet_templates();
308 }
309 }
310
311 private function add_breakpoints_controls() {
312 $default_breakpoints_config = Breakpoints_Manager::get_default_config();
313 $prefix = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX;
314
315 // If the ACB experiment is inactive, only add the mobile and tablet controls.
316 if ( ! Plugin::$instance->experiments->is_feature_active( 'additional_custom_breakpoints' ) ) {
317 $default_breakpoints_config = array_intersect_key( $default_breakpoints_config, array_flip( [ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE, Breakpoints_Manager::BREAKPOINT_KEY_TABLET ] ) );
318 }
319
320 // Add a control for each of the **default** breakpoints.
321 foreach ( $default_breakpoints_config as $breakpoint_key => $default_breakpoint_config ) {
322 $this->add_control(
323 'breakpoint_' . $breakpoint_key . '_heading',
324 [
325 'label' => $default_breakpoint_config['label'],
326 'type' => Controls_Manager::HEADING,
327 'separator' => 'before',
328 'conditions' => [
329 'terms' => [
330 [
331 'name' => 'active_breakpoints',
332 'operator' => 'contains',
333 'value' => $prefix . $breakpoint_key,
334 ],
335 ],
336 ],
337 ]
338 );
339
340 $control_config = [
341 'label' => esc_html__( 'Breakpoint', 'elementor' ) . ' (px)',
342 'type' => Controls_Manager::NUMBER,
343 'placeholder' => $default_breakpoint_config['default_value'],
344 'frontend_available' => true,
345 'validators' => [
346 'Breakpoint' => [
347 'breakpointName' => $breakpoint_key,
348 ],
349 ],
350 'conditions' => [
351 'terms' => [
352 [
353 'name' => 'active_breakpoints',
354 'operator' => 'contains',
355 'value' => $prefix . $breakpoint_key,
356 ],
357 ],
358 ],
359 ];
360
361 if ( Breakpoints_Manager::BREAKPOINT_KEY_WIDESCREEN === $breakpoint_key ) {
362 $control_config['description'] = esc_html__(
363 'Widescreen breakpoint settings will apply from the selected value and up.',
364 'elementor'
365 );
366 }
367
368 // Add the breakpoint Control itself.
369 $this->add_control( $prefix . $breakpoint_key, $control_config );
370 }
371 }
372 }
373