← All changes
|
modules/atomic-widgets/elements/base/atomic-element-base.php
+31
-37
4.2.2
→
3.35.7
View file →
| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Elementor\Modules\AtomicWidgets\Elements\Base; |
| 4 | 4 | |
| 5 | 5 | use Elementor\Element_Base; |
| 6 | +use Elementor\Modules\AtomicWidgets\Elements\Loader\Frontend_Assets_Loader; | |
| 6 | 7 | use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager; |
| 7 | 8 | use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type; |
| 8 | 9 | use Elementor\Modules\AtomicWidgets\PropTypes\Concerns\Has_Meta; |
| 9 | 10 | use Elementor\Plugin; |
| @@ -20,9 +21,8 @@ | ||
| 20 | 21 | protected $version = '0.0'; |
| 21 | 22 | protected $styles = []; |
| 22 | 23 | protected $interactions = []; |
| 23 | 24 | protected $editor_settings = []; |
| 24 | - protected $origin_id = null; | |
| 25 | 25 | |
| 26 | 26 | public static $widget_description = null; |
| 27 | 27 | |
| 28 | 28 | |
| @@ -32,14 +32,12 @@ | ||
| 32 | 32 | $this->version = $data['version'] ?? '0.0'; |
| 33 | 33 | $this->styles = $data['styles'] ?? []; |
| 34 | 34 | $this->interactions = $this->parse_atomic_interactions( $data['interactions'] ?? [] ); |
| 35 | 35 | $this->editor_settings = $data['editor_settings'] ?? []; |
| 36 | - | |
| 36 | + $this->add_script_depends( Frontend_Assets_Loader::ATOMIC_WIDGETS_HANDLER ); | |
| 37 | 37 | if ( static::$widget_description ) { |
| 38 | 38 | $this->description( static::$widget_description ); |
| 39 | 39 | } |
| 40 | - | |
| 41 | - $this->origin_id = $data['origin_id'] ?? null; | |
| 42 | 40 | } |
| 43 | 41 | |
| 44 | 42 | private function parse_atomic_interactions( $interactions ) { |
| 45 | 43 | if ( empty( $interactions ) ) { |
| @@ -59,8 +57,28 @@ | ||
| 59 | 57 | |
| 60 | 58 | return $interactions; |
| 61 | 59 | } |
| 62 | 60 | |
| 61 | + private function convert_prop_type_interactions_to_legacy_for_runtime( $interactions ) { | |
| 62 | + $legacy_items = []; | |
| 63 | + | |
| 64 | + foreach ( $interactions['items'] as $item ) { | |
| 65 | + if ( isset( $item['$$type'] ) && 'interaction-item' === $item['$$type'] ) { | |
| 66 | + $legacy_item = $this->extract_legacy_interaction_from_prop_type( $item ); | |
| 67 | + if ( $legacy_item ) { | |
| 68 | + $legacy_items[] = $legacy_item; | |
| 69 | + } | |
| 70 | + } else { | |
| 71 | + $legacy_items[] = $item; | |
| 72 | + } | |
| 73 | + } | |
| 74 | + | |
| 75 | + return [ | |
| 76 | + 'version' => $interactions['version'] ?? 1, | |
| 77 | + 'items' => $legacy_items, | |
| 78 | + ]; | |
| 79 | + } | |
| 80 | + | |
| 63 | 81 | abstract protected function define_atomic_controls(): array; |
| 64 | 82 | |
| 65 | 83 | protected function define_atomic_style_states(): array { |
| 66 | 84 | return []; |
| @@ -65,31 +83,24 @@ | ||
| 65 | 83 | protected function define_atomic_style_states(): array { |
| 66 | 84 | return []; |
| 67 | 85 | } |
| 68 | 86 | |
| 69 | - protected function define_atomic_pseudo_states(): array { | |
| 70 | - return []; | |
| 71 | - } | |
| 72 | - | |
| 73 | 87 | public function get_global_scripts() { |
| 74 | 88 | return []; |
| 75 | 89 | } |
| 76 | 90 | |
| 77 | - protected function get_initial_config() { | |
| 91 | + final public function get_initial_config() { | |
| 78 | 92 | $config = parent::get_initial_config(); |
| 79 | 93 | $props_schema = static::get_props_schema(); |
| 80 | 94 | |
| 81 | - $config['atomic'] = true; | |
| 82 | 95 | $config['atomic_controls'] = $this->get_atomic_controls(); |
| 83 | 96 | $config['atomic_props_schema'] = $props_schema; |
| 84 | 97 | $config['atomic_style_states'] = $this->define_atomic_style_states(); |
| 85 | - $config['atomic_pseudo_states'] = $this->define_atomic_pseudo_states(); | |
| 86 | 98 | $config['dependencies_per_target_mapping'] = Dependency_Manager::get_source_to_dependents( $props_schema ); |
| 87 | 99 | $config['base_styles'] = $this->get_base_styles(); |
| 88 | - $config['base_settings'] = $this->get_base_settings(); | |
| 89 | 100 | $config['version'] = $this->version; |
| 90 | 101 | $config['show_in_panel'] = $this->should_show_in_panel(); |
| 91 | - $config['categories'] = $this->define_panel_categories(); | |
| 102 | + $config['categories'] = [ 'v4-elements' ]; | |
| 92 | 103 | $config['hide_on_search'] = false; |
| 93 | 104 | $config['controls'] = []; |
| 94 | 105 | $config['keywords'] = $this->get_keywords(); |
| 95 | 106 | $config['default_children'] = $this->define_default_children(); |
| @@ -96,9 +107,8 @@ | ||
| 96 | 107 | $config['initial_attributes'] = $this->define_initial_attributes(); |
| 97 | 108 | $config['include_in_widgets_config'] = true; |
| 98 | 109 | $config['default_html_tag'] = $this->define_default_html_tag(); |
| 99 | 110 | $config['meta'] = $this->get_meta(); |
| 100 | - $config['allowed_child_types'] = $this->define_allowed_child_types(); | |
| 101 | 111 | |
| 102 | 112 | return $config; |
| 103 | 113 | } |
| 104 | 114 | |
| @@ -105,12 +115,8 @@ | ||
| 105 | 115 | protected function should_show_in_panel() { |
| 106 | 116 | return true; |
| 107 | 117 | } |
| 108 | 118 | |
| 109 | - protected function define_panel_categories(): array { | |
| 110 | - return [ 'v4-elements' ]; | |
| 111 | - } | |
| 112 | - | |
| 113 | 119 | protected function define_default_children() { |
| 114 | 120 | return []; |
| 115 | 121 | } |
| 116 | 122 | |
| @@ -121,20 +127,17 @@ | ||
| 121 | 127 | protected function define_initial_attributes() { |
| 122 | 128 | return []; |
| 123 | 129 | } |
| 124 | 130 | |
| 125 | - protected function define_allowed_child_types() { | |
| 126 | - return []; | |
| 127 | - } | |
| 128 | - | |
| 129 | - protected function get_interaction_id() { | |
| 130 | - return $this->origin_id ?? $this->get_id(); | |
| 131 | - } | |
| 132 | - | |
| 133 | 131 | protected function add_render_attributes() { |
| 134 | 132 | parent::add_render_attributes(); |
| 135 | 133 | |
| 136 | - $this->add_render_attribute( '_wrapper', 'data-interaction-id', $this->get_interaction_id() ); | |
| 134 | + $interaction_ids = $this->get_interactions_ids(); | |
| 135 | + | |
| 136 | + if ( ! empty( $interaction_ids ) ) { | |
| 137 | + $this->add_render_attribute( '_wrapper', 'data-interaction-id', $this->get_id() ); | |
| 138 | + $this->add_render_attribute( '_wrapper', 'data-interactions', json_encode( $interaction_ids ) ); | |
| 139 | + } | |
| 137 | 140 | } |
| 138 | 141 | |
| 139 | 142 | /** |
| 140 | 143 | * Get Element keywords. |
| @@ -163,13 +166,9 @@ | ||
| 163 | 166 | protected function get_html_tag(): string { |
| 164 | 167 | $settings = $this->get_atomic_settings(); |
| 165 | 168 | $default_html_tag = $this->define_default_html_tag(); |
| 166 | 169 | |
| 167 | - if ( ! empty( $settings['link']['tag'] ) ) { | |
| 168 | - return $settings['link']['tag']; | |
| 169 | - } | |
| 170 | - | |
| 171 | - return $settings['tag'] ?? $default_html_tag; | |
| 170 | + return ! empty( $settings['link']['href'] ) ? $settings['link']['tag'] : ( $settings['tag'] ?? $default_html_tag ); | |
| 172 | 171 | } |
| 173 | 172 | |
| 174 | 173 | /** |
| 175 | 174 | * Print safe HTML tag for the element based on the element settings. |
| @@ -188,13 +187,8 @@ | ||
| 188 | 187 | */ |
| 189 | 188 | protected function print_custom_attributes() { |
| 190 | 189 | $settings = $this->get_atomic_settings(); |
| 191 | 190 | $attributes = $settings['attributes'] ?? ''; |
| 192 | - | |
| 193 | - if ( isset( $settings['link']['attributes'] ) ) { | |
| 194 | - $attributes .= ' ' . ( $settings['link']['attributes'] ?? '' ); | |
| 195 | - } | |
| 196 | - | |
| 197 | 191 | if ( ! empty( $attributes ) && is_string( $attributes ) ) { |
| 198 | 192 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 199 | 193 | echo ' ' . $attributes; |
| 200 | 194 | } |