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

173 lines 4.6 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\Html_Tag_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 'newValue' => [
51 '$$type' => 'string',
52 'value' => 'a',
53 ],
54 ] )
55 ->get();
56
57 return [
58 'classes' => Classes_Prop_Type::make()
59 ->default( [] ),
60 'tag' => String_Prop_Type::make()
61 ->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer', 'a' ] )
62 ->default( 'div' )
63 ->set_dependencies( $tag_dependencies ),
64 'link' => Link_Prop_Type::make(),
65 'attributes' => Attributes_Prop_Type::make(),
66 ];
67 }
68
69 protected function define_atomic_controls(): array {
70 return [
71 Section::make()
72 ->set_label( __( 'Settings', 'elementor' ) )
73 ->set_id( 'settings' )
74 ->set_items( [
75 Html_Tag_Control::bind_to( 'tag' )
76 ->set_options( [
77 [
78 'value' => 'div',
79 'label' => 'Div',
80 ],
81 [
82 'value' => 'header',
83 'label' => 'Header',
84 ],
85 [
86 'value' => 'section',
87 'label' => 'Section',
88 ],
89 [
90 'value' => 'article',
91 'label' => 'Article',
92 ],
93 [
94 'value' => 'aside',
95 'label' => 'Aside',
96 ],
97 [
98 'value' => 'footer',
99 'label' => 'Footer',
100 ],
101 ])
102 ->set_fallback_labels( [
103 'a' => 'a (link)',
104 ] )
105 ->set_label( esc_html__( 'HTML Tag', 'elementor' ) ),
106 Link_Control::bind_to( 'link' )
107 ->set_placeholder( __( 'Type or paste your URL', 'elementor' ) )
108 ->set_label( __( 'Link', 'elementor' ) )
109 ->set_meta( [
110 'topDivider' => true,
111 ] ),
112 Text_Control::bind_to( '_cssid' )
113 ->set_label( __( 'ID', 'elementor' ) )
114 ->set_meta( $this->get_css_id_control_meta() ),
115 ] ),
116 ];
117 }
118
119 protected function define_base_styles(): array {
120 $display = String_Prop_Type::generate( 'block' );
121
122 return [
123 static::BASE_STYLE_KEY => Style_Definition::make()
124 ->add_variant(
125 Style_Variant::make()
126 ->add_prop( 'display', $display )
127 ->add_prop( 'padding', $this->get_base_padding() )
128 ->add_prop( 'min-width', $this->get_base_min_width() )
129 ),
130 ];
131 }
132
133 protected function get_base_padding(): array {
134 return Size_Prop_Type::generate( [
135 'size' => 10,
136 'unit' => 'px',
137 ] );
138 }
139
140 protected function get_base_min_width(): array {
141 return Size_Prop_Type::generate( [
142 'size' => 30,
143 'unit' => 'px',
144 ] );
145 }
146
147 protected function add_render_attributes() {
148 parent::add_render_attributes();
149 $settings = $this->get_atomic_settings();
150 $base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ];
151 $initial_attributes = $this->define_initial_attributes();
152
153 $attributes = [
154 'class' => [
155 'e-con',
156 'e-atomic-element',
157 $base_style_class,
158 ...( $settings['classes'] ?? [] ),
159 ],
160 ];
161
162 if ( ! empty( $settings['_cssid'] ) ) {
163 $attributes['id'] = esc_attr( $settings['_cssid'] );
164 }
165
166 if ( ! empty( $settings['link']['href'] ) ) {
167 $attributes = array_merge( $attributes, $settings['link'] );
168 }
169
170 $this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) );
171 }
172 }
173