PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
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 4.3.0-beta3, at modules/atomic-widgets/elements/div-block/div-block.php

211 lines 6.0 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\Base\Atomic_Element_Base;
5 use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Element_Template;
6 use Elementor\Modules\AtomicWidgets\Elements\Base\Html_Tag_Computer;
7 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
8 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
9 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
10 use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
11 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
12 use Elementor\Modules\AtomicWidgets\Controls\Section;
13 use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control;
14 use Elementor\Modules\AtomicWidgets\Controls\Types\Html_Tag_Control;
15 use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
16 use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager;
17 use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
18 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
19 use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
20
21 if ( ! defined( 'ABSPATH' ) ) {
22 exit; // Exit if accessed directly.
23 }
24
25 class Div_Block extends Atomic_Element_Base {
26 use Has_Element_Template;
27
28 const BASE_STYLE_KEY = 'base';
29
30 public function __construct( $data = [], $args = null ) {
31 parent::__construct( $data, $args );
32 $this->meta( 'is_container', true );
33 }
34
35 public static function get_type() {
36 return 'e-div-block';
37 }
38
39 public static function get_element_type(): string {
40 return 'e-div-block';
41 }
42
43 public function get_title() {
44 return esc_html__( 'Div block', 'elementor' );
45 }
46
47 public function get_keywords() {
48 return [ 'ato', 'atom', 'atoms', 'atomic', 'container', 'wrapper', 'section', 'row', 'column', 'div', 'box', 'layout' ];
49 }
50
51 public function get_icon() {
52 return 'eicon-div-block';
53 }
54
55 public static function get_computed_html_tag( array $settings ): string {
56 return Html_Tag_Computer::compute( $settings, 'div' );
57 }
58
59 protected static function define_props_schema(): array {
60 $tag_dependencies = Dependency_Manager::make( Dependency_Manager::RELATION_AND )
61 ->where( [
62 'operator' => 'ne',
63 'path' => [ 'link', 'destination' ],
64 'nestedPath' => [ 'group' ],
65 'value' => 'action',
66 'newValue' => [
67 '$$type' => 'string',
68 'value' => 'button',
69 ],
70 ] )->where( [
71 'operator' => 'not_exist',
72 'path' => [ 'link', 'destination' ],
73 'newValue' => [
74 '$$type' => 'string',
75 'value' => 'a',
76 ],
77 ] )->get();
78
79 return [
80 'classes' => Classes_Prop_Type::make()
81 ->default( [] ),
82 'tag' => String_Prop_Type::make()
83 ->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer', 'a', 'button', 'main', 'nav' ] )
84 ->default( 'div' )
85 ->description( 'The HTML tag for the div block container. One of: div, header, section, article, aside, footer, main, nav, a (link), or button. Do not use heading or paragraph tags.' )
86 ->set_dependencies( $tag_dependencies ),
87 'link' => Link_Prop_Type::make(),
88 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
89 ];
90 }
91
92 protected function define_atomic_controls(): array {
93 return [
94 Section::make()
95 ->set_label( __( 'Settings', 'elementor' ) )
96 ->set_id( 'settings' )
97 ->set_items( [
98 Html_Tag_Control::bind_to( 'tag' )
99 ->set_options( [
100 [
101 'value' => 'div',
102 'label' => 'Div',
103 ],
104 [
105 'value' => 'header',
106 'label' => 'Header',
107 ],
108 [
109 'value' => 'section',
110 'label' => 'Section',
111 ],
112 [
113 'value' => 'article',
114 'label' => 'Article',
115 ],
116 [
117 'value' => 'aside',
118 'label' => 'Aside',
119 ],
120 [
121 'value' => 'footer',
122 'label' => 'Footer',
123 ],
124 [
125 'value' => 'main',
126 'label' => 'Main',
127 ],
128 [
129 'value' => 'nav',
130 'label' => 'Nav',
131 ],
132 ])
133 ->set_fallback_labels( [
134 'a' => 'a (link)',
135 ] )
136 ->set_label( esc_html__( 'HTML Tag', 'elementor' ) ),
137 Link_Control::bind_to( 'link' )
138 ->set_placeholder( __( 'Type or paste your URL', 'elementor' ) )
139 ->set_label( __( 'Link', 'elementor' ) )
140 ->set_meta( [
141 'topDivider' => true,
142 ] ),
143 Text_Control::bind_to( '_cssid' )
144 ->set_label( __( 'ID', 'elementor' ) )
145 ->set_meta( $this->get_css_id_control_meta() ),
146 ] ),
147 ];
148 }
149
150 protected function define_base_styles(): array {
151 $display = String_Prop_Type::generate( 'block' );
152
153 return [
154 static::BASE_STYLE_KEY => Style_Definition::make()
155 ->add_variant(
156 Style_Variant::make()
157 ->add_prop( 'display', $display )
158 ->add_prop( 'padding', $this->get_base_padding() )
159 ->add_prop( 'min-width', $this->get_base_min_width() )
160 ),
161 ];
162 }
163
164 protected function get_base_padding(): array {
165 return Size_Prop_Type::generate( [
166 'size' => 10,
167 'unit' => 'px',
168 ] );
169 }
170
171 protected function get_base_min_width(): array {
172 return Size_Prop_Type::generate( [
173 'size' => 30,
174 'unit' => 'px',
175 ] );
176 }
177
178 protected function add_render_attributes() {
179 parent::add_render_attributes();
180 $settings = $this->get_atomic_settings();
181 $base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ];
182 $initial_attributes = $this->define_initial_attributes();
183
184 $attributes = [
185 'class' => [
186 'e-con',
187 'e-atomic-element',
188 $base_style_class,
189 ...( $settings['classes'] ?? [] ),
190 ],
191 ];
192
193 if ( ! empty( $settings['_cssid'] ) ) {
194 $attributes['id'] = esc_attr( $settings['_cssid'] );
195 }
196
197 if ( ! empty( $settings['link']['href'] ) ) {
198 $link_attributes = $this->get_link_attributes( $settings['link'] );
199 $attributes = array_merge( $attributes, $link_attributes );
200 }
201
202 $this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) );
203 }
204
205 protected function get_templates(): array {
206 return [
207 'elementor/elements/div-block' => __DIR__ . '/div-block.html.twig',
208 ];
209 }
210 }
211