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