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

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