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

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