1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
<?php namespace Elementor\Modules\AtomicWidgets\Elements;
use Elementor\Modules\AtomicWidgets\Base\Atomic_Element_Base; use Elementor\Modules\AtomicWidgets\Controls\Section; use Elementor\Modules\AtomicWidgets\Controls\Types\Select_Control; use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; use Elementor\Plugin; use Elementor\Utils;
if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. }
class Div_Block extends Atomic_Element_Base { public static function get_type() { return 'div-block'; }
public function get_name() { return 'div-block'; }
public function get_title() { return esc_html__( 'Div Block', 'elementor' ); }
public function get_icon() { return 'eicon-div-block'; }
public function get_style_depends() { return [ 'div-block' ]; }
protected function define_atomic_controls(): array { return [ Section::make() ->set_label( __( 'Settings', 'elementor' ) ) ->set_items( [ Select_Control::bind_to( 'tag' ) ->set_label( esc_html__( 'HTML Tag', 'elementor' ) ) ->set_options( [ [ 'value' => 'div', 'label' => 'Div', ], [ 'value' => 'header', 'label' => 'Header', ], [ 'value' => 'section', 'label' => 'Section', ], [ 'value' => 'article', 'label' => 'Article', ], [ 'value' => 'aside', 'label' => 'Aside', ], [ 'value' => 'footer', 'label' => 'Footer', ], ]), ]), ]; }
protected static function define_props_schema(): array { return [ 'classes' => Classes_Prop_Type::make() ->default( [] ),
'tag' => String_Prop_Type::make() ->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer' ] ) ->default( 'div' ), ]; }
protected function _get_default_child_type( array $element_data ) { if ( 'div-block' === $element_data['elType'] ) { return Plugin::$instance->elements_manager->get_element_types( 'div-block' ); }
return Plugin::$instance->widgets_manager->get_widget_types( $element_data['widgetType'] ); }
protected function content_template() { ?> <?php }
protected function add_render_attributes() { parent::add_render_attributes(); $settings = $this->get_atomic_settings();
$this->add_render_attribute( '_wrapper', [ 'class' => [ 'e-div-block', $settings['classes'] ?? '', ], ] ); }
public function before_render() { ?> <<?php $this->print_html_tag(); ?> <?php $this->print_render_attribute_string( '_wrapper' ); ?>> <?php }
public function after_render() { ?> </<?php $this->print_html_tag(); ?>> <?php }
/** * Print safe HTML tag for the element based on the element settings. * * @return void */ protected function print_html_tag() { $html_tag = $this->get_atomic_settings()['tag'] ?? 'div'; Utils::print_validated_html_tag( $html_tag ); } }
|