| 1 |
<?php |
| 2 |
namespace Elementor\Core\Kits\Documents\Tabs; |
| 3 |
|
| 4 |
use Elementor\DB; |
| 5 |
use Elementor\Plugin; |
| 6 |
use Elementor\Controls_Manager; |
| 7 |
use Elementor\Core\Responsive\Responsive; |
| 8 |
use Elementor\Modules\PageTemplates\Module as PageTemplatesModule; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; // Exit if accessed directly |
| 12 |
} |
| 13 |
|
| 14 |
class Settings_Layout extends Tab_Base { |
| 15 |
|
| 16 |
public function get_id() { |
| 17 |
return 'settings-layout'; |
| 18 |
} |
| 19 |
|
| 20 |
public function get_title() { |
| 21 |
return __( 'Layout', 'elementor' ); |
| 22 |
} |
| 23 |
|
| 24 |
protected function register_tab_controls() { |
| 25 |
$default_breakpoints = Responsive::get_default_breakpoints(); |
| 26 |
|
| 27 |
$this->start_controls_section( |
| 28 |
'section_' . $this->get_id(), |
| 29 |
[ |
| 30 |
'label' => __( 'Layout Settings', 'elementor' ), |
| 31 |
'tab' => $this->get_id(), |
| 32 |
] |
| 33 |
); |
| 34 |
|
| 35 |
$this->add_responsive_control( |
| 36 |
'container_width', |
| 37 |
[ |
| 38 |
'label' => __( 'Content Width', 'elementor' ) . ' (px)', |
| 39 |
'type' => Controls_Manager::SLIDER, |
| 40 |
'default' => [ |
| 41 |
'size' => '1140', |
| 42 |
], |
| 43 |
'tablet_default' => [ |
| 44 |
'size' => $default_breakpoints['lg'], |
| 45 |
], |
| 46 |
'mobile_default' => [ |
| 47 |
'size' => $default_breakpoints['md'], |
| 48 |
], |
| 49 |
'range' => [ |
| 50 |
'px' => [ |
| 51 |
'min' => 300, |
| 52 |
'max' => 1500, |
| 53 |
'step' => 10, |
| 54 |
], |
| 55 |
], |
| 56 |
'description' => __( 'Sets the default width of the content area (Default: 1140)', 'elementor' ), |
| 57 |
'selectors' => [ |
| 58 |
'.elementor-section.elementor-section-boxed > .elementor-container' => 'max-width: {{SIZE}}{{UNIT}}', |
| 59 |
], |
| 60 |
] |
| 61 |
); |
| 62 |
|
| 63 |
$this->add_control( |
| 64 |
'space_between_widgets', |
| 65 |
[ |
| 66 |
'label' => __( 'Widgets Space', 'elementor' ) . ' (px)', |
| 67 |
'type' => Controls_Manager::SLIDER, |
| 68 |
'default' => [ |
| 69 |
'size' => 20, |
| 70 |
], |
| 71 |
'range' => [ |
| 72 |
'px' => [ |
| 73 |
'min' => 0, |
| 74 |
'max' => 40, |
| 75 |
], |
| 76 |
], |
| 77 |
'placeholder' => '20', |
| 78 |
'description' => __( 'Sets the default space between widgets (Default: 20)', 'elementor' ), |
| 79 |
'selectors' => [ |
| 80 |
'.elementor-widget:not(:last-child)' => 'margin-bottom: {{SIZE}}{{UNIT}}', |
| 81 |
], |
| 82 |
] |
| 83 |
); |
| 84 |
|
| 85 |
$this->add_control( |
| 86 |
'page_title_selector', |
| 87 |
[ |
| 88 |
'label' => __( 'Page Title Selector', 'elementor' ), |
| 89 |
'type' => Controls_Manager::TEXT, |
| 90 |
'default' => 'h1.entry-title', |
| 91 |
'placeholder' => 'h1.entry-title', |
| 92 |
'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' ), |
| 93 |
'label_block' => true, |
| 94 |
'selectors' => [ |
| 95 |
// Hack to convert the value into a CSS selector. |
| 96 |
'' => '}{{VALUE}}{display: var(--page-title-display)', |
| 97 |
], |
| 98 |
] |
| 99 |
); |
| 100 |
|
| 101 |
$this->add_control( |
| 102 |
'stretched_section_container', |
| 103 |
[ |
| 104 |
'label' => __( 'Stretched Section Fit To', 'elementor' ), |
| 105 |
'type' => Controls_Manager::TEXT, |
| 106 |
'placeholder' => 'body', |
| 107 |
'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' ), |
| 108 |
'label_block' => true, |
| 109 |
'frontend_available' => true, |
| 110 |
] |
| 111 |
); |
| 112 |
|
| 113 |
/** |
| 114 |
* @var PageTemplatesModule $page_templates_module |
| 115 |
*/ |
| 116 |
$page_templates_module = Plugin::$instance->modules_manager->get_modules( 'page-templates' ); |
| 117 |
$page_templates = $page_templates_module->add_page_templates( [], null, null ); |
| 118 |
|
| 119 |
$page_template_control_options = [ |
| 120 |
'label' => __( 'Default Page Layout', 'elementor' ), |
| 121 |
'options' => [ |
| 122 |
// This is here because the "Theme" string is different than the default option's string. |
| 123 |
'default' => __( 'Theme', 'elementor' ), |
| 124 |
] + $page_templates, |
| 125 |
]; |
| 126 |
|
| 127 |
$page_templates_module->add_template_controls( $this->parent, 'default_page_template', $page_template_control_options ); |
| 128 |
|
| 129 |
$this->end_controls_section(); |
| 130 |
|
| 131 |
$this->start_controls_section( |
| 132 |
'section_breakpoints', |
| 133 |
[ |
| 134 |
'label' => __( 'Breakpoints', 'elementor' ), |
| 135 |
'tab' => $this->get_id(), |
| 136 |
] |
| 137 |
); |
| 138 |
|
| 139 |
$this->add_control( |
| 140 |
'breakpoint_md_heading', |
| 141 |
[ |
| 142 |
'label' => __( 'Mobile', 'elementor' ), |
| 143 |
'type' => Controls_Manager::HEADING, |
| 144 |
] |
| 145 |
); |
| 146 |
|
| 147 |
$this->add_control( |
| 148 |
Responsive::BREAKPOINT_OPTION_PREFIX . 'md', |
| 149 |
[ |
| 150 |
'label' => __( 'Breakpoint', 'elementor' ) . ' (px)', |
| 151 |
'type' => Controls_Manager::NUMBER, |
| 152 |
'min' => $default_breakpoints['sm'] + 1, |
| 153 |
'max' => $default_breakpoints['lg'] - 1, |
| 154 |
'default' => $default_breakpoints['md'], |
| 155 |
'placeholder' => $default_breakpoints['md'], |
| 156 |
/* translators: %d: Breakpoint value */ |
| 157 |
'desc' => sprintf( __( 'Sets the breakpoint between tablet and mobile devices. Below this breakpoint mobile layout will appear (Default: %dpx).', 'elementor' ), $default_breakpoints['md'] ), |
| 158 |
] |
| 159 |
); |
| 160 |
|
| 161 |
$this->add_control( |
| 162 |
'breakpoint_lg_heading', |
| 163 |
[ |
| 164 |
'label' => __( 'Tablet', 'elementor' ), |
| 165 |
'type' => Controls_Manager::HEADING, |
| 166 |
] |
| 167 |
); |
| 168 |
|
| 169 |
$this->add_control( |
| 170 |
Responsive::BREAKPOINT_OPTION_PREFIX . 'lg', |
| 171 |
[ |
| 172 |
'label' => __( 'Breakpoint', 'elementor' ) . ' (px)', |
| 173 |
'type' => Controls_Manager::NUMBER, |
| 174 |
'min' => $default_breakpoints['md'] + 1, |
| 175 |
'max' => $default_breakpoints['xl'] - 1, |
| 176 |
'default' => $default_breakpoints['lg'], |
| 177 |
'placeholder' => $default_breakpoints['lg'], |
| 178 |
/* translators: %d: Breakpoint value */ |
| 179 |
'desc' => sprintf( __( 'Sets the breakpoint between desktop and tablet devices. Below this breakpoint tablet layout will appear (Default: %dpx).', 'elementor' ), $default_breakpoints['lg'] ), |
| 180 |
] |
| 181 |
); |
| 182 |
|
| 183 |
$this->end_controls_section(); |
| 184 |
} |
| 185 |
|
| 186 |
public function on_save( $data ) { |
| 187 |
if ( ! isset( $data['settings'] ) || DB::STATUS_PUBLISH !== $data['settings']['post_status'] ) { |
| 188 |
return; |
| 189 |
} |
| 190 |
|
| 191 |
$should_compile_css = false; |
| 192 |
|
| 193 |
foreach ( Responsive::get_editable_breakpoints() as $breakpoint_key => $breakpoint ) { |
| 194 |
$setting_key = "viewport_{$breakpoint_key}"; |
| 195 |
if ( isset( $data['settings'][ $setting_key ] ) ) { |
| 196 |
$should_compile_css = true; |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
if ( $should_compile_css ) { |
| 201 |
Responsive::compile_stylesheet_templates(); |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
|