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

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