PluginProbe
Elementor Website Builder – more than just a page builder / 3.31.4
Elementor Website Builder – more than just a page builder v3.31.4
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 +111 -93 4.2.0-beta2 → 3.31.4 View file →
@@ -1,22 +1,20 @@
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;
4 +use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control;
5 +use Elementor\Modules\AtomicWidgets\Elements\Atomic_Element_Base;
6 +use Elementor\Modules\AtomicWidgets\Controls\Types\Select_Control;
7 +use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager;
8 +use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
9 +use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
6 10 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
7 11 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
8 12 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
9 -use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
13 +use Elementor\Modules\AtomicWidgets\PropTypes\Key_Value_Array_Prop_Type;
10 14 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
11 -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;
16 -use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
17 -use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
18 -use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
15 +use Elementor\Plugin;
16 +use Elementor\Utils;
19 17
20 18 if ( ! defined( 'ABSPATH' ) ) {
21 19 exit; // Exit if accessed directly.
22 20 }
@@ -21,17 +19,10 @@
21 19 exit; // Exit if accessed directly.
22 20 }
23 21
24 22 class Div_Block extends Atomic_Element_Base {
25 - use Has_Element_Template;
26 -
27 23 const BASE_STYLE_KEY = 'base';
28 24
29 - public function __construct( $data = [], $args = null ) {
30 - parent::__construct( $data, $args );
31 - $this->meta( 'is_container', true );
32 - }
33 -
34 25 public static function get_type() {
35 26 return 'e-div-block';
36 27 }
37 28
@@ -39,13 +30,13 @@
39 30 return 'e-div-block';
40 31 }
41 32
42 33 public function get_title() {
43 - return esc_html__( 'Div block', 'elementor' );
34 + return esc_html__( 'Div Block', 'elementor' );
44 35 }
45 36
46 37 public function get_keywords() {
47 - return [ 'ato', 'atom', 'atoms', 'atomic', 'layout' ];
38 + return [ 'ato', 'atom', 'atoms', 'atomic' ];
48 39 }
49 40
50 41 public function get_icon() {
51 42 return 'eicon-div-block';
@@ -51,89 +42,125 @@
51 42 return 'eicon-div-block';
52 43 }
53 44
54 45 protected static function define_props_schema(): array {
55 - $tag_dependencies = Dependency_Manager::make( Dependency_Manager::RELATION_AND )
46 + $tag_dependencies = Dependency_Manager::make()
56 47 ->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 48 'operator' => 'not_exist',
67 49 'path' => [ 'link', 'destination' ],
68 - 'newValue' => [
69 - '$$type' => 'string',
70 - 'value' => 'a',
71 - ],
72 - ] )->get();
50 + ] )
51 + ->get();
73 52
74 - return [
53 + $props = [
75 54 'classes' => Classes_Prop_Type::make()
76 55 ->default( [] ),
77 56 'tag' => String_Prop_Type::make()
78 - ->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer', 'a', 'button' ] )
57 + ->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer' ] )
79 58 ->default( 'div' )
80 59 ->set_dependencies( $tag_dependencies ),
81 60 'link' => Link_Prop_Type::make(),
82 - 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
61 +
62 + 'attributes' => Key_Value_Array_Prop_Type::make(),
83 63 ];
64 +
65 + return $props;
84 66 }
85 67
86 68 protected function define_atomic_controls(): array {
69 + return [];
70 + }
71 +
72 + protected function get_settings_controls(): array {
87 73 return [
88 - Section::make()
89 - ->set_label( __( 'Settings', 'elementor' ) )
90 - ->set_id( 'settings' )
91 - ->set_items( [
92 - Html_Tag_Control::bind_to( 'tag' )
93 - ->set_options( [
94 - [
95 - 'value' => 'div',
96 - 'label' => 'Div',
97 - ],
98 - [
99 - 'value' => 'header',
100 - 'label' => 'Header',
101 - ],
102 - [
103 - 'value' => 'section',
104 - 'label' => 'Section',
105 - ],
106 - [
107 - 'value' => 'article',
108 - 'label' => 'Article',
109 - ],
110 - [
111 - 'value' => 'aside',
112 - 'label' => 'Aside',
113 - ],
114 - [
115 - 'value' => 'footer',
116 - 'label' => 'Footer',
117 - ],
118 - ])
119 - ->set_fallback_labels( [
120 - 'a' => 'a (link)',
121 - ] )
122 - ->set_label( esc_html__( 'HTML Tag', 'elementor' ) ),
123 - 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() ),
74 + Select_Control::bind_to( 'tag' )
75 + ->set_label( esc_html__( 'HTML Tag', 'elementor' ) )
76 + ->set_options( [
77 + [
78 + 'value' => 'div',
79 + 'label' => 'Div',
80 + ],
81 + [
82 + 'value' => 'header',
83 + 'label' => 'Header',
84 + ],
85 + [
86 + 'value' => 'section',
87 + 'label' => 'Section',
88 + ],
89 + [
90 + 'value' => 'article',
91 + 'label' => 'Article',
92 + ],
93 + [
94 + 'value' => 'aside',
95 + 'label' => 'Aside',
96 + ],
97 + [
98 + 'value' => 'footer',
99 + 'label' => 'Footer',
100 + ],
101 + ]),
102 + Link_Control::bind_to( 'link' )
103 + ->set_label( __( 'Link', 'elementor' ) )
104 + ->set_meta( [
105 + 'topDivider' => true,
132 106 ] ),
133 107 ];
134 108 }
135 109
110 + protected function _get_default_child_type( array $element_data ) {
111 + $el_types = array_keys( Plugin::$instance->elements_manager->get_element_types() );
112 +
113 + if ( in_array( $element_data['elType'], $el_types, true ) ) {
114 + return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] );
115 + }
116 +
117 + return Plugin::$instance->widgets_manager->get_widget_types( $element_data['widgetType'] );
118 + }
119 +
120 + protected function content_template() {
121 + ?>
122 + <?php
123 + }
124 +
125 + public function before_render() {
126 + ?>
127 + <<?php $this->print_html_tag(); ?> <?php $this->print_render_attribute_string( '_wrapper' );
128 + $this->print_custom_attributes(); ?>>
129 + <?php
130 + }
131 +
132 + public function after_render() {
133 + ?>
134 + </<?php $this->print_html_tag(); ?>>
135 + <?php
136 + }
137 +
138 + private function print_custom_attributes() {
139 + $settings = $this->get_atomic_settings();
140 + $attributes = $settings['attributes'];
141 + if ( ! empty( $attributes ) && is_string( $attributes ) ) {
142 + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
143 + echo ' ' . $attributes;
144 + }
145 + }
146 +
147 + /**
148 + * Print safe HTML tag for the element based on the element settings.
149 + *
150 + * @return void
151 + */
152 + protected function print_html_tag() {
153 + $html_tag = $this->get_html_tag();
154 + Utils::print_validated_html_tag( $html_tag );
155 + }
156 +
157 + protected function get_html_tag(): string {
158 + $settings = $this->get_atomic_settings();
159 +
160 + return ! empty( $settings['link']['href'] ) ? 'a' : ( $settings['tag'] ?? 'div' );
161 + }
162 +
136 163 protected function define_base_styles(): array {
137 164 $display = String_Prop_Type::generate( 'block' );
138 165
139 166 return [
@@ -164,14 +191,12 @@
164 191 protected function add_render_attributes() {
165 192 parent::add_render_attributes();
166 193 $settings = $this->get_atomic_settings();
167 194 $base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ];
168 - $initial_attributes = $this->define_initial_attributes();
169 195
170 196 $attributes = [
171 197 'class' => [
172 198 'e-con',
173 - 'e-atomic-element',
174 199 $base_style_class,
175 200 ...( $settings['classes'] ?? [] ),
176 201 ],
177 202 ];
@@ -180,17 +205,10 @@
180 205 $attributes['id'] = esc_attr( $settings['_cssid'] );
181 206 }
182 207
183 208 if ( ! empty( $settings['link']['href'] ) ) {
184 - $link_attributes = $this->get_link_attributes( $settings['link'] );
185 - $attributes = array_merge( $attributes, $link_attributes );
209 + $attributes = array_merge( $attributes, $settings['link'] );
186 210 }
187 211
188 - $this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) );
189 - }
190 -
191 - protected function get_templates(): array {
192 - return [
193 - 'elementor/elements/div-block' => __DIR__ . '/div-block.html.twig',
194 - ];
212 + $this->add_render_attribute( '_wrapper', $attributes );
195 213 }
196 214 }