PluginProbe
Elementor Website Builder – more than just a page builder / 3.33.0-beta1
Elementor Website Builder – more than just a page builder v3.33.0-beta1
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 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / atomic-widgets / elements / atomic-element-base.php

atomic-element-base.php in Elementor Website Builder – more than just a page builder 3.33.0-beta1, at modules/atomic-widgets/elements/atomic-element-base.php

182 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\AtomicWidgets\Elements;
4
5 use Elementor\Element_Base;
6 use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager;
7 use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type;
8 use Elementor\Plugin;
9 use Elementor\Utils;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 abstract class Atomic_Element_Base extends Element_Base {
16 use Has_Atomic_Base;
17
18 protected $version = '0.0';
19 protected $styles = [];
20 protected $editor_settings = [];
21
22 public function __construct( $data = [], $args = null ) {
23 parent::__construct( $data, $args );
24
25 $this->version = $data['version'] ?? '0.0';
26 $this->styles = $data['styles'] ?? [];
27 $this->editor_settings = $data['editor_settings'] ?? [];
28 }
29
30 abstract protected function define_atomic_controls(): array;
31
32 public function get_global_scripts() {
33 return [];
34 }
35
36 final public function get_initial_config() {
37 $config = parent::get_initial_config();
38 $props_schema = static::get_props_schema();
39
40 $config['atomic_controls'] = $this->get_atomic_controls();
41 $config['atomic_props_schema'] = $props_schema;
42 $config['dependencies_per_target_mapping'] = Dependency_Manager::get_source_to_dependents( $props_schema );
43 $config['base_styles'] = $this->get_base_styles();
44 $config['version'] = $this->version;
45 $config['show_in_panel'] = $this->should_show_in_panel();
46 $config['categories'] = [ 'v4-elements' ];
47 $config['hide_on_search'] = false;
48 $config['controls'] = [];
49 $config['keywords'] = $this->get_keywords();
50 $config['default_children'] = $this->define_default_children();
51 $config['initial_attributes'] = $this->define_initial_attributes();
52 $config['include_in_widgets_config'] = true;
53 $config['default_html_tag'] = $this->define_default_html_tag();
54
55 return $config;
56 }
57
58 protected function should_show_in_panel() {
59 return true;
60 }
61
62 protected function define_default_children() {
63 return [];
64 }
65
66 protected function define_default_html_tag() {
67 return 'div';
68 }
69
70 protected function define_initial_attributes() {
71 return [];
72 }
73
74 /**
75 * Get Element keywords.
76 *
77 * Retrieve the element keywords.
78 *
79 * @since 3.29
80 * @access public
81 *
82 * @return array Element keywords.
83 */
84 public function get_keywords() {
85 return [];
86 }
87
88 /**
89 * @return array<string, Prop_Type>
90 */
91 abstract protected static function define_props_schema(): array;
92
93 /**
94 * Get the HTML tag for rendering.
95 *
96 * @return string
97 */
98 protected function get_html_tag(): string {
99 $settings = $this->get_atomic_settings();
100 $default_html_tag = $this->define_default_html_tag();
101
102 return ! empty( $settings['link']['href'] ) ? 'a' : ( $settings['tag'] ?? $default_html_tag );
103 }
104
105 /**
106 * Print safe HTML tag for the element based on the element settings.
107 *
108 * @return void
109 */
110 protected function print_html_tag() {
111 $html_tag = $this->get_html_tag();
112 Utils::print_validated_html_tag( $html_tag );
113 }
114
115 /**
116 * Print custom attributes if they exist.
117 *
118 * @return void
119 */
120 protected function print_custom_attributes() {
121 $settings = $this->get_atomic_settings();
122 $attributes = $settings['attributes'] ?? '';
123 if ( ! empty( $attributes ) && is_string( $attributes ) ) {
124 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
125 echo ' ' . $attributes;
126 }
127 }
128
129 /**
130 * Get default child type for container elements.
131 *
132 * @param array $element_data
133 * @return mixed
134 */
135 protected function _get_default_child_type( array $element_data ) {
136 $el_types = array_keys( Plugin::$instance->elements_manager->get_element_types() );
137
138 if ( in_array( $element_data['elType'], $el_types, true ) ) {
139 return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] );
140 }
141
142 return Plugin::$instance->widgets_manager->get_widget_types( $element_data['widgetType'] );
143 }
144
145 /**
146 * Default before render for container elements.
147 *
148 * @return void
149 */
150 public function before_render() {
151 ?>
152 <<?php $this->print_html_tag(); ?> <?php $this->print_render_attribute_string( '_wrapper' );
153 $this->print_custom_attributes(); ?>>
154 <?php
155 }
156
157 /**
158 * Default after render for container elements.
159 *
160 * @return void
161 */
162 public function after_render() {
163 ?>
164 </<?php $this->print_html_tag(); ?>>
165 <?php
166 }
167
168 /**
169 * Default content template - can be overridden by elements that need custom templates.
170 *
171 * @return void
172 */
173 protected function content_template() {
174 ?>
175 <?php
176 }
177
178 public static function generate() {
179 return Element_Builder::make( static::get_type() );
180 }
181 }
182