PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.0-dev4
Elementor Website Builder – more than just a page builder v4.0.0-dev4
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 / base / atomic-widget-base.php

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

107 lines 2.9 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\Base;
4
5 use Elementor\Modules\AtomicWidgets\Elements\Loader\Frontend_Assets_Loader;
6 use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager;
7 use Elementor\Modules\AtomicWidgets\PropTypes\Concerns\Has_Meta;
8 use Elementor\Widget_Base;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 abstract class Atomic_Widget_Base extends Widget_Base {
15 use Has_Atomic_Base;
16 use Has_Meta;
17
18 public static $widget_description = null;
19
20 protected $version = '0.0';
21 protected $styles = [];
22 protected $interactions = [];
23 protected $editor_settings = [];
24 protected $origin_id = null;
25
26 public function __construct( $data = [], $args = null ) {
27 parent::__construct( $data, $args );
28
29 $this->version = $data['version'] ?? '0.0';
30 $this->styles = $data['styles'] ?? [];
31 $this->interactions = $this->parse_atomic_interactions( $data['interactions'] ?? [] );
32 $this->editor_settings = $data['editor_settings'] ?? [];
33 if ( static::$widget_description ) {
34 $this->description( static::$widget_description );
35 }
36 $this->origin_id = $data['origin_id'] ?? null;
37 }
38
39 private function parse_atomic_interactions( $interactions ) {
40 if ( empty( $interactions ) ) {
41 return [];
42 }
43
44 if ( is_string( $interactions ) ) {
45 $decoded = json_decode( $interactions, true );
46 if ( json_last_error() === JSON_ERROR_NONE && is_array( $decoded ) ) {
47 $interactions = $decoded;
48 }
49 }
50
51 if ( ! is_array( $interactions ) ) {
52 return [];
53 }
54
55 return $interactions;
56 }
57
58 abstract protected function define_atomic_controls(): array;
59
60 protected function define_atomic_pseudo_states(): array {
61 return [];
62 }
63
64 public function get_global_scripts() {
65 return [];
66 }
67
68 public function get_initial_config() {
69 $config = parent::get_initial_config();
70 $props_schema = static::get_props_schema();
71
72 $config['atomic'] = true;
73 $config['atomic_controls'] = $this->get_atomic_controls();
74 $config['base_styles'] = $this->get_base_styles();
75 $config['base_styles_dictionary'] = $this->get_base_styles_dictionary();
76 $config['atomic_props_schema'] = $props_schema;
77 $config['atomic_pseudo_states'] = $this->define_atomic_pseudo_states();
78 $config['dependencies_per_target_mapping'] = Dependency_Manager::get_source_to_dependents( $props_schema );
79 $config['version'] = $this->version;
80 $config['meta'] = $this->get_meta();
81
82 return $config;
83 }
84
85 public function get_categories(): array {
86 return [ 'v4-elements' ];
87 }
88
89 public function before_render() {}
90
91 public function after_render() {}
92
93 abstract protected static function define_props_schema(): array;
94
95 public static function generate() {
96 return Widget_Builder::make( static::get_element_type() );
97 }
98
99 public function get_script_depends() {
100 return [ Frontend_Assets_Loader::ATOMIC_WIDGETS_HANDLER ];
101 }
102
103 public function get_interaction_id() {
104 return $this->origin_id ?? $this->get_id();
105 }
106 }
107