PluginProbe
Elementor Website Builder – more than just a page builder / 3.30.2
Elementor Website Builder – more than just a page builder v3.30.2
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 / modules / atomic-widgets / elements / div-block / div-block.php

div-block.php in Elementor Website Builder – more than just a page builder 3.30.2, at modules/atomic-widgets/elements/div-block/div-block.php

212 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\AtomicWidgets\Elements\Div_Block;
3
4 use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control;
5 use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
6 use Elementor\Modules\AtomicWidgets\Elements\Atomic_Element_Base;
7 use Elementor\Modules\AtomicWidgets\Controls\Section;
8 use Elementor\Modules\AtomicWidgets\Controls\Types\Select_Control;
9 use Elementor\Modules\AtomicWidgets\Module;
10 use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
11 use Elementor\Modules\AtomicWidgets\PropTypes\Color_Prop_Type;
12 use Elementor\Modules\AtomicWidgets\PropTypes\Dimensions_Prop_Type;
13 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
14 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
15 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
16 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
17 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
18 use Elementor\Plugin;
19 use Elementor\Utils;
20
21 if ( ! defined( 'ABSPATH' ) ) {
22 exit; // Exit if accessed directly.
23 }
24
25 class Div_Block extends Atomic_Element_Base {
26 const BASE_STYLE_KEY = 'base';
27
28 public static function get_type() {
29 return 'e-div-block';
30 }
31
32 public static function get_element_type(): string {
33 return 'e-div-block';
34 }
35
36 public function get_title() {
37 return esc_html__( 'Div Block', 'elementor' );
38 }
39
40 public function get_keywords() {
41 return [ 'ato', 'atom', 'atoms', 'atomic' ];
42 }
43
44 public function get_icon() {
45 return 'eicon-div-block';
46 }
47
48 protected static function define_props_schema(): array {
49 $props = [
50 'classes' => Classes_Prop_Type::make()
51 ->default( [] ),
52
53 'tag' => String_Prop_Type::make()
54 ->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer' ] )
55 ->default( 'div' ),
56
57 'link' => Link_Prop_Type::make(),
58 ];
59
60 if ( Plugin::$instance->experiments->is_feature_active( Module::EXPERIMENT_VERSION_3_30 ) ) {
61 $props['_cssid'] = String_Prop_Type::make();
62 }
63
64 return $props;
65 }
66
67 protected function define_atomic_controls(): array {
68 $settings_section_items = [
69 Select_Control::bind_to( 'tag' )
70 ->set_label( esc_html__( 'HTML Tag', 'elementor' ) )
71 ->set_options( [
72 [
73 'value' => 'div',
74 'label' => 'Div',
75 ],
76 [
77 'value' => 'header',
78 'label' => 'Header',
79 ],
80 [
81 'value' => 'section',
82 'label' => 'Section',
83 ],
84 [
85 'value' => 'article',
86 'label' => 'Article',
87 ],
88 [
89 'value' => 'aside',
90 'label' => 'Aside',
91 ],
92 [
93 'value' => 'footer',
94 'label' => 'Footer',
95 ],
96 ]),
97
98 Link_Control::bind_to( 'link' )->set_meta( [
99 'topDivider' => true,
100 ] ),
101 ];
102
103 if ( Plugin::$instance->experiments->is_feature_active( Module::EXPERIMENT_VERSION_3_30 ) ) {
104 $settings_section_items[] = Text_Control::bind_to( '_cssid' )->set_label( __( 'ID', 'elementor' ) )->set_meta( [
105 'layout' => 'two-columns',
106 'topDivider' => true,
107 ] );
108 }
109
110 return [
111 Section::make()
112 ->set_label( __( 'Settings', 'elementor' ) )
113 ->set_items( $settings_section_items ),
114 ];
115 }
116
117 protected function _get_default_child_type( array $element_data ) {
118 $el_types = array_keys( Plugin::$instance->elements_manager->get_element_types() );
119
120 if ( in_array( $element_data['elType'], $el_types, true ) ) {
121 return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] );
122 }
123
124 return Plugin::$instance->widgets_manager->get_widget_types( $element_data['widgetType'] );
125 }
126
127 protected function content_template() {
128 ?>
129 <?php
130 }
131
132 public function before_render() {
133 ?>
134 <<?php $this->print_html_tag(); ?> <?php $this->print_render_attribute_string( '_wrapper' ); ?>>
135 <?php
136 }
137
138 public function after_render() {
139 ?>
140 </<?php $this->print_html_tag(); ?>>
141 <?php
142 }
143
144 /**
145 * Print safe HTML tag for the element based on the element settings.
146 *
147 * @return void
148 */
149 protected function print_html_tag() {
150 $html_tag = $this->get_html_tag();
151 Utils::print_validated_html_tag( $html_tag );
152 }
153
154 protected function get_html_tag(): string {
155 $settings = $this->get_atomic_settings();
156
157 return ! empty( $settings['link']['href'] ) ? 'a' : ( $settings['tag'] ?? 'div' );
158 }
159
160 protected function define_base_styles(): array {
161 $display = String_Prop_Type::generate( 'block' );
162
163 return [
164 static::BASE_STYLE_KEY => Style_Definition::make()
165 ->add_variant(
166 Style_Variant::make()
167 ->add_prop( 'display', $display )
168 ->add_prop( 'padding', $this->get_base_padding() )
169 ->add_prop( 'min-width', $this->get_base_min_width() )
170 ),
171 ];
172 }
173
174 protected function get_base_padding(): array {
175 return Size_Prop_Type::generate( [
176 'size' => 10,
177 'unit' => 'px',
178 ] );
179 }
180
181 protected function get_base_min_width(): array {
182 return Size_Prop_Type::generate( [
183 'size' => 30,
184 'unit' => 'px',
185 ] );
186 }
187
188 protected function add_render_attributes() {
189 parent::add_render_attributes();
190 $settings = $this->get_atomic_settings();
191 $base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ];
192
193 $attributes = [
194 'class' => [
195 'e-con',
196 $base_style_class,
197 ...( $settings['classes'] ?? [] ),
198 ],
199 ];
200
201 if ( ! empty( $settings['_cssid'] ) ) {
202 $attributes['id'] = esc_attr( $settings['_cssid'] );
203 }
204
205 if ( ! empty( $settings['link']['href'] ) ) {
206 $attributes = array_merge( $attributes, $settings['link'] );
207 }
208
209 $this->add_render_attribute( '_wrapper', $attributes );
210 }
211 }
212