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

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