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

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