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