PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.0-dev2
Elementor Website Builder – more than just a page builder v3.32.0-dev2
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.32.0-dev2, at modules/atomic-widgets/elements/atomic-element-base.php

171 lines 4.1 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['include_in_widgets_config'] = true;
52
53 return $config;
54 }
55
56 protected function should_show_in_panel() {
57 return true;
58 }
59
60 protected function define_default_children() {
61 return [];
62 }
63
64 /**
65 * Get Element keywords.
66 *
67 * Retrieve the element keywords.
68 *
69 * @since 3.29
70 * @access public
71 *
72 * @return array Element keywords.
73 */
74 public function get_keywords() {
75 return [];
76 }
77
78 /**
79 * @return array<string, Prop_Type>
80 */
81 abstract protected static function define_props_schema(): array;
82
83 /**
84 * Get the HTML tag for rendering.
85 *
86 * @return string
87 */
88 protected function get_html_tag(): string {
89 $settings = $this->get_atomic_settings();
90
91 return ! empty( $settings['link']['href'] ) ? 'a' : ( $settings['tag'] ?? 'div' );
92 }
93
94 /**
95 * Print safe HTML tag for the element based on the element settings.
96 *
97 * @return void
98 */
99 protected function print_html_tag() {
100 $html_tag = $this->get_html_tag();
101 Utils::print_validated_html_tag( $html_tag );
102 }
103
104 /**
105 * Print custom attributes if they exist.
106 *
107 * @return void
108 */
109 protected function print_custom_attributes() {
110 $settings = $this->get_atomic_settings();
111 $attributes = $settings['attributes'];
112 if ( ! empty( $attributes ) && is_string( $attributes ) ) {
113 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
114 echo ' ' . $attributes;
115 }
116 }
117
118 /**
119 * Get default child type for container elements.
120 *
121 * @param array $element_data
122 * @return mixed
123 */
124 protected function _get_default_child_type( array $element_data ) {
125 $el_types = array_keys( Plugin::$instance->elements_manager->get_element_types() );
126
127 if ( in_array( $element_data['elType'], $el_types, true ) ) {
128 return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] );
129 }
130
131 return Plugin::$instance->widgets_manager->get_widget_types( $element_data['widgetType'] );
132 }
133
134 /**
135 * Default before render for container elements.
136 *
137 * @return void
138 */
139 public function before_render() {
140 ?>
141 <<?php $this->print_html_tag(); ?> <?php $this->print_render_attribute_string( '_wrapper' );
142 $this->print_custom_attributes(); ?>>
143 <?php
144 }
145
146 /**
147 * Default after render for container elements.
148 *
149 * @return void
150 */
151 public function after_render() {
152 ?>
153 </<?php $this->print_html_tag(); ?>>
154 <?php
155 }
156
157 /**
158 * Default content template - can be overridden by elements that need custom templates.
159 *
160 * @return void
161 */
162 protected function content_template() {
163 ?>
164 <?php
165 }
166
167 public static function generate() {
168 return Element_Builder::make( static::get_type() );
169 }
170 }
171