PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.0-beta1
Elementor Website Builder – more than just a page builder v3.28.0-beta1
4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 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 All 457 releases
← All changes | modules/atomic-widgets/elements/div-block/div-block.php +61 -97 4.0.9 → 3.28.0-beta1 View file →
@@ -1,21 +1,16 @@
1 1 <?php
2 2 namespace Elementor\Modules\AtomicWidgets\Elements\Div_Block;
3 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;
4 +use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control;
5 +use Elementor\Modules\AtomicWidgets\Elements\Atomic_Element_Base;
10 6 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;
7 +use Elementor\Modules\AtomicWidgets\Controls\Types\Select_Control;
15 8 use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
16 9 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
17 -use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
10 +use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
11 +use Elementor\Plugin;
12 +use Elementor\Utils;
18 13
19 14 if ( ! defined( 'ABSPATH' ) ) {
20 15 exit; // Exit if accessed directly.
21 16 }
@@ -20,64 +15,34 @@
20 15 exit; // Exit if accessed directly.
21 16 }
22 17
23 18 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 19 public static function get_type() {
32 - return 'e-div-block';
20 + return 'div-block';
33 21 }
34 22
35 23 public static function get_element_type(): string {
36 - return 'e-div-block';
24 + return 'div-block';
37 25 }
38 26
39 27 public function get_title() {
40 - return esc_html__( 'Div block', 'elementor' );
28 + return esc_html__( 'Div Block', 'elementor' );
41 29 }
42 30
43 - public function get_keywords() {
44 - return [ 'ato', 'atom', 'atoms', 'atomic' ];
45 - }
46 -
47 31 public function get_icon() {
48 32 return 'eicon-div-block';
49 33 }
50 34
51 35 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 36 return [
72 37 'classes' => Classes_Prop_Type::make()
73 38 ->default( [] ),
39 +
74 40 'tag' => String_Prop_Type::make()
75 - ->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer', 'a', 'button' ] )
76 - ->default( 'div' )
77 - ->set_dependencies( $tag_dependencies ),
41 + ->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer' ] )
42 + ->default( 'div' ),
43 +
78 44 'link' => Link_Prop_Type::make(),
79 - 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
80 45 ];
81 46 }
82 47
83 48 protected function define_atomic_controls(): array {
@@ -83,11 +48,11 @@
83 48 protected function define_atomic_controls(): array {
84 49 return [
85 50 Section::make()
86 51 ->set_label( __( 'Settings', 'elementor' ) )
87 - ->set_id( 'settings' )
88 52 ->set_items( [
89 - Html_Tag_Control::bind_to( 'tag' )
53 + Select_Control::bind_to( 'tag' )
54 + ->set_label( esc_html__( 'HTML Tag', 'elementor' ) )
90 55 ->set_options( [
91 56 [
92 57 'value' => 'div',
93 58 'label' => 'Div',
@@ -111,77 +76,76 @@
111 76 [
112 77 'value' => 'footer',
113 78 'label' => 'Footer',
114 79 ],
115 - ])
116 - ->set_fallback_labels( [
117 - 'a' => 'a (link)',
118 - ] )
119 - ->set_label( esc_html__( 'HTML Tag', 'elementor' ) ),
80 + ]),
81 +
120 82 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 - ] ),
83 + ->set_placeholder( __( 'Paste URL or type', 'elementor' ) ),
84 + ]),
130 85 ];
131 86 }
132 87
133 - protected function define_base_styles(): array {
134 - $display = String_Prop_Type::generate( 'block' );
88 + public function get_style_depends() {
89 + return [ 'div-block' ];
90 + }
135 91
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 - }
92 + protected function _get_default_child_type( array $element_data ) {
93 + if ( 'div-block' === $element_data['elType'] ) {
94 + return Plugin::$instance->elements_manager->get_element_types( 'div-block' );
95 + }
146 96
147 - protected function get_base_padding(): array {
148 - return Size_Prop_Type::generate( [
149 - 'size' => 10,
150 - 'unit' => 'px',
151 - ] );
97 + return Plugin::$instance->widgets_manager->get_widget_types( $element_data['widgetType'] );
152 98 }
153 99
154 - protected function get_base_min_width(): array {
155 - return Size_Prop_Type::generate( [
156 - 'size' => 30,
157 - 'unit' => 'px',
158 - ] );
100 + protected function content_template() {
101 + ?>
102 + <?php
159 103 }
160 104
161 105 protected function add_render_attributes() {
162 106 parent::add_render_attributes();
163 107 $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 108
167 109 $attributes = [
168 110 'class' => [
169 111 'e-con',
170 - 'e-atomic-element',
171 - $base_style_class,
112 + 'e-div-block',
172 113 ...( $settings['classes'] ?? [] ),
173 114 ],
174 115 ];
175 116
176 - if ( ! empty( $settings['_cssid'] ) ) {
177 - $attributes['id'] = esc_attr( $settings['_cssid'] );
117 + if ( ! empty( $settings['link']['href'] ) ) {
118 + $attributes = array_merge( $attributes, $settings['link'] );
178 119 }
179 120
180 - if ( ! empty( $settings['link']['href'] ) ) {
181 - $link_attributes = $this->get_link_attributes( $settings['link'] );
182 - $attributes = array_merge( $attributes, $link_attributes );
183 - }
121 + $this->add_render_attribute( '_wrapper', $attributes );
122 + }
184 123
185 - $this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) );
124 + public function before_render() {
125 + ?>
126 + <<?php $this->print_html_tag(); ?> <?php $this->print_render_attribute_string( '_wrapper' ); ?>>
127 + <?php
128 + }
129 +
130 + public function after_render() {
131 + ?>
132 + </<?php $this->print_html_tag(); ?>>
133 + <?php
134 + }
135 +
136 + /**
137 + * Print safe HTML tag for the element based on the element settings.
138 + *
139 + * @return void
140 + */
141 + protected function print_html_tag() {
142 + $html_tag = $this->get_html_tag();
143 + Utils::print_validated_html_tag( $html_tag );
144 + }
145 +
146 + protected function get_html_tag(): string {
147 + $settings = $this->get_atomic_settings();
148 +
149 + return ! empty( $settings['link']['href'] ) ? 'a' : ( $settings['tag'] ?? 'div' );
186 150 }
187 151 }