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

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

164 lines 4.3 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\Elements\Atomic_Element_Base;
5 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
6 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
7 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
8 use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
9 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
10 use Elementor\Modules\AtomicWidgets\Controls\Section;
11 use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control;
12 use Elementor\Modules\AtomicWidgets\Controls\Types\Select_Control;
13 use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
14 use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager;
15 use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
16 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit; // Exit if accessed directly.
20 }
21
22 class Div_Block extends Atomic_Element_Base {
23 const BASE_STYLE_KEY = 'base';
24
25 public static function get_type() {
26 return 'e-div-block';
27 }
28
29 public static function get_element_type(): string {
30 return 'e-div-block';
31 }
32
33 public function get_title() {
34 return esc_html__( 'Div Block', 'elementor' );
35 }
36
37 public function get_keywords() {
38 return [ 'ato', 'atom', 'atoms', 'atomic' ];
39 }
40
41 public function get_icon() {
42 return 'eicon-div-block';
43 }
44
45 protected static function define_props_schema(): array {
46 $tag_dependencies = Dependency_Manager::make()
47 ->where( [
48 'operator' => 'not_exist',
49 'path' => [ 'link', 'destination' ],
50 ] )
51 ->get();
52
53 return [
54 'classes' => Classes_Prop_Type::make()
55 ->default( [] ),
56 'tag' => String_Prop_Type::make()
57 ->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer' ] )
58 ->default( 'div' )
59 ->set_dependencies( $tag_dependencies ),
60 'link' => Link_Prop_Type::make(),
61 'attributes' => Attributes_Prop_Type::make(),
62 ];
63 }
64
65 protected function define_atomic_controls(): array {
66 return [
67 Section::make()
68 ->set_label( __( 'Settings', 'elementor' ) )
69 ->set_id( 'settings' )
70 ->set_items( [
71 Select_Control::bind_to( 'tag' )
72 ->set_options( [
73 [
74 'value' => 'div',
75 'label' => 'Div',
76 ],
77 [
78 'value' => 'header',
79 'label' => 'Header',
80 ],
81 [
82 'value' => 'section',
83 'label' => 'Section',
84 ],
85 [
86 'value' => 'article',
87 'label' => 'Article',
88 ],
89 [
90 'value' => 'aside',
91 'label' => 'Aside',
92 ],
93 [
94 'value' => 'footer',
95 'label' => 'Footer',
96 ],
97 ])
98 ->set_label( esc_html__( 'HTML Tag', 'elementor' ) ),
99 Link_Control::bind_to( 'link' )
100 ->set_label( __( 'Link', 'elementor' ) )
101 ->set_meta( [
102 'topDivider' => true,
103 ] ),
104 Text_Control::bind_to( '_cssid' )
105 ->set_label( __( 'ID', 'elementor' ) )
106 ->set_meta( $this->get_css_id_control_meta() ),
107 ] ),
108 ];
109 }
110
111 protected function define_base_styles(): array {
112 $display = String_Prop_Type::generate( 'block' );
113
114 return [
115 static::BASE_STYLE_KEY => Style_Definition::make()
116 ->add_variant(
117 Style_Variant::make()
118 ->add_prop( 'display', $display )
119 ->add_prop( 'padding', $this->get_base_padding() )
120 ->add_prop( 'min-width', $this->get_base_min_width() )
121 ),
122 ];
123 }
124
125 protected function get_base_padding(): array {
126 return Size_Prop_Type::generate( [
127 'size' => 10,
128 'unit' => 'px',
129 ] );
130 }
131
132 protected function get_base_min_width(): array {
133 return Size_Prop_Type::generate( [
134 'size' => 30,
135 'unit' => 'px',
136 ] );
137 }
138
139 protected function add_render_attributes() {
140 parent::add_render_attributes();
141 $settings = $this->get_atomic_settings();
142 $base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ];
143
144 $attributes = [
145 'class' => [
146 'e-con',
147 'e-atomic-element',
148 $base_style_class,
149 ...( $settings['classes'] ?? [] ),
150 ],
151 ];
152
153 if ( ! empty( $settings['_cssid'] ) ) {
154 $attributes['id'] = esc_attr( $settings['_cssid'] );
155 }
156
157 if ( ! empty( $settings['link']['href'] ) ) {
158 $attributes = array_merge( $attributes, $settings['link'] );
159 }
160
161 $this->add_render_attribute( '_wrapper', $attributes );
162 }
163 }
164