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