PluginProbe
Elementor Website Builder – more than just a page builder / 3.34.3
Elementor Website Builder – more than just a page builder v3.34.3
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-widget-base.php

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

106 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\AtomicWidgets\Elements;
3
4 use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager;
5 use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type;
6 use Elementor\Widget_Base;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 abstract class Atomic_Widget_Base extends Widget_Base {
13 use Has_Atomic_Base;
14
15 protected $version = '0.0';
16 protected $styles = [];
17 protected $interactions = [];
18 protected $editor_settings = [];
19
20 public function __construct( $data = [], $args = null ) {
21 parent::__construct( $data, $args );
22
23 $this->version = $data['version'] ?? '0.0';
24 $this->styles = $data['styles'] ?? [];
25 $this->interactions = $this->parse_atomic_interactions( $data['interactions'] ?? [] );
26 $this->editor_settings = $data['editor_settings'] ?? [];
27 }
28
29 private function parse_atomic_interactions( $interactions ) {
30 if ( empty( $interactions ) ) {
31 return [];
32 }
33
34 if ( is_string( $interactions ) ) {
35 $decoded = json_decode( $interactions, true );
36 if ( json_last_error() === JSON_ERROR_NONE && is_array( $decoded ) ) {
37 $interactions = $decoded;
38 }
39 }
40
41 if ( ! is_array( $interactions ) ) {
42 return [];
43 }
44
45 if ( isset( $interactions['items'] ) && is_array( $interactions['items'] ) ) {
46 return $this->convert_prop_type_interactions_to_legacy_for_runtime( $interactions );
47 }
48
49 return $interactions;
50 }
51
52 private function convert_prop_type_interactions_to_legacy_for_runtime( $interactions ) {
53 $legacy_items = [];
54
55 foreach ( $interactions['items'] as $item ) {
56 if ( isset( $item['$$type'] ) && 'interaction-item' === $item['$$type'] ) {
57 $legacy_item = $this->extract_legacy_interaction_from_prop_type( $item );
58 if ( $legacy_item ) {
59 $legacy_items[] = $legacy_item;
60 }
61 } else {
62 $legacy_items[] = $item;
63 }
64 }
65
66 return [
67 'version' => $interactions['version'] ?? 1,
68 'items' => $legacy_items,
69 ];
70 }
71
72 abstract protected function define_atomic_controls(): array;
73
74 public function get_global_scripts() {
75 return [];
76 }
77
78 public function get_initial_config() {
79 $config = parent::get_initial_config();
80 $props_schema = static::get_props_schema();
81
82 $config['atomic'] = true;
83 $config['atomic_controls'] = $this->get_atomic_controls();
84 $config['base_styles'] = $this->get_base_styles();
85 $config['base_styles_dictionary'] = $this->get_base_styles_dictionary();
86 $config['atomic_props_schema'] = $props_schema;
87 $config['dependencies_per_target_mapping'] = Dependency_Manager::get_source_to_dependents( $props_schema );
88 $config['version'] = $this->version;
89
90 return $config;
91 }
92
93 public function get_categories(): array {
94 return [ 'v4-elements' ];
95 }
96
97 public function before_render() {}
98 public function after_render() {}
99
100 abstract protected static function define_props_schema(): array;
101
102 public static function generate() {
103 return Widget_Builder::make( static::get_element_type() );
104 }
105 }
106