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

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