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

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