← All changes
|
modules/atomic-widgets/elements/base/atomic-element-base.php
+37
-79
4.3.0-beta3
→
3.35.0-dev2
View file →
| @@ -2,9 +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\ChildrenDependencies\Child_Dependency; | |
| 6 | +use Elementor\Modules\AtomicWidgets\Elements\Loader\Frontend_Assets_Loader; | |
| 7 | 7 | use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager; |
| 8 | 8 | use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type; |
| 9 | 9 | use Elementor\Modules\AtomicWidgets\PropTypes\Concerns\Has_Meta; |
| 10 | 10 | use Elementor\Plugin; |
| @@ -17,25 +17,12 @@ | ||
| 17 | 17 | abstract class Atomic_Element_Base extends Element_Base { |
| 18 | 18 | use Has_Atomic_Base; |
| 19 | 19 | use Has_Meta; |
| 20 | 20 | |
| 21 | - /** | |
| 22 | - * Maps atomic element type → the minor version when the "New" badge expires. | |
| 23 | - * Format: 'element-type' => 'major.minor' (patch is ignored during comparison). | |
| 24 | - * | |
| 25 | - * @var array<string, string> | |
| 26 | - */ | |
| 27 | - private const NEW_ATOMIC_ELEMENTS = [ | |
| 28 | - 'e-background-video' => '4.3', | |
| 29 | - 'e-accordion' => '4.3', | |
| 30 | - 'e-list' => '4.3', | |
| 31 | - ]; | |
| 32 | - | |
| 33 | 21 | protected $version = '0.0'; |
| 34 | 22 | protected $styles = []; |
| 35 | 23 | protected $interactions = []; |
| 36 | 24 | protected $editor_settings = []; |
| 37 | - protected $origin_id = null; | |
| 38 | 25 | |
| 39 | 26 | public static $widget_description = null; |
| 40 | 27 | |
| 41 | 28 | |
| @@ -45,14 +32,12 @@ | ||
| 45 | 32 | $this->version = $data['version'] ?? '0.0'; |
| 46 | 33 | $this->styles = $data['styles'] ?? []; |
| 47 | 34 | $this->interactions = $this->parse_atomic_interactions( $data['interactions'] ?? [] ); |
| 48 | 35 | $this->editor_settings = $data['editor_settings'] ?? []; |
| 49 | - | |
| 36 | + $this->add_script_depends( Frontend_Assets_Loader::ATOMIC_WIDGETS_HANDLER ); | |
| 50 | 37 | if ( static::$widget_description ) { |
| 51 | 38 | $this->description( static::$widget_description ); |
| 52 | 39 | } |
| 53 | - | |
| 54 | - $this->origin_id = $data['origin_id'] ?? null; | |
| 55 | 40 | } |
| 56 | 41 | |
| 57 | 42 | private function parse_atomic_interactions( $interactions ) { |
| 58 | 43 | if ( empty( $interactions ) ) { |
| @@ -72,8 +57,28 @@ | ||
| 72 | 57 | |
| 73 | 58 | return $interactions; |
| 74 | 59 | } |
| 75 | 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 | + | |
| 76 | 81 | abstract protected function define_atomic_controls(): array; |
| 77 | 82 | |
| 78 | 83 | protected function define_atomic_style_states(): array { |
| 79 | 84 | return []; |
| @@ -78,43 +83,32 @@ | ||
| 78 | 83 | protected function define_atomic_style_states(): array { |
| 79 | 84 | return []; |
| 80 | 85 | } |
| 81 | 86 | |
| 82 | - protected function define_atomic_pseudo_states(): array { | |
| 83 | - return []; | |
| 84 | - } | |
| 85 | - | |
| 86 | 87 | public function get_global_scripts() { |
| 87 | 88 | return []; |
| 88 | 89 | } |
| 89 | 90 | |
| 90 | - protected function get_initial_config() { | |
| 91 | + final public function get_initial_config() { | |
| 91 | 92 | $config = parent::get_initial_config(); |
| 92 | 93 | $props_schema = static::get_props_schema(); |
| 93 | 94 | |
| 94 | - $config['atomic'] = true; | |
| 95 | 95 | $config['atomic_controls'] = $this->get_atomic_controls(); |
| 96 | 96 | $config['atomic_props_schema'] = $props_schema; |
| 97 | 97 | $config['atomic_style_states'] = $this->define_atomic_style_states(); |
| 98 | - $config['atomic_pseudo_states'] = $this->define_atomic_pseudo_states(); | |
| 99 | 98 | $config['dependencies_per_target_mapping'] = Dependency_Manager::get_source_to_dependents( $props_schema ); |
| 100 | 99 | $config['base_styles'] = $this->get_base_styles(); |
| 101 | - $config['base_settings'] = $this->get_base_settings(); | |
| 102 | 100 | $config['version'] = $this->version; |
| 103 | 101 | $config['show_in_panel'] = $this->should_show_in_panel(); |
| 104 | - $config['categories'] = $this->define_panel_categories(); | |
| 102 | + $config['categories'] = [ 'v4-elements' ]; | |
| 105 | 103 | $config['hide_on_search'] = false; |
| 106 | 104 | $config['controls'] = []; |
| 107 | 105 | $config['keywords'] = $this->get_keywords(); |
| 108 | 106 | $config['default_children'] = $this->define_default_children(); |
| 109 | - $config['children_dependencies'] = $this->get_children_dependencies_config(); | |
| 110 | 107 | $config['initial_attributes'] = $this->define_initial_attributes(); |
| 111 | 108 | $config['include_in_widgets_config'] = true; |
| 112 | - $config['default_html_tag'] = static::get_computed_html_tag( [] ); | |
| 113 | - $config['html_tag_follows_link'] = static::html_tag_follows_link(); | |
| 109 | + $config['default_html_tag'] = $this->define_default_html_tag(); | |
| 114 | 110 | $config['meta'] = $this->get_meta(); |
| 115 | - $config['allowed_child_types'] = $this->define_allowed_child_types(); | |
| 116 | - $config['new_until_version'] = self::NEW_ATOMIC_ELEMENTS[ $this->get_name() ] ?? ''; | |
| 117 | 111 | |
| 118 | 112 | return $config; |
| 119 | 113 | } |
| 120 | 114 | |
| @@ -121,63 +115,29 @@ | ||
| 121 | 115 | protected function should_show_in_panel() { |
| 122 | 116 | return true; |
| 123 | 117 | } |
| 124 | 118 | |
| 125 | - protected function define_panel_categories(): array { | |
| 126 | - return [ 'v4-elements' ]; | |
| 127 | - } | |
| 128 | - | |
| 129 | 119 | protected function define_default_children() { |
| 130 | 120 | return []; |
| 131 | 121 | } |
| 132 | 122 | |
| 133 | - /** | |
| 134 | - * Declare settings→children reconcile rules for this element. | |
| 135 | - * | |
| 136 | - * Each rule ties a `Dependency_Manager` condition on this element's | |
| 137 | - * settings to the presence of a specific child element type. The generic | |
| 138 | - * client-side reconciler (`@elementor/editor-elements/children-dependencies`) | |
| 139 | - * attaches / detaches the child at the model layer as the condition flips, | |
| 140 | - * without per-widget v1 hooks. | |
| 141 | - * | |
| 142 | - * @return Child_Dependency[] | |
| 143 | - */ | |
| 144 | - protected function define_children_dependencies(): array { | |
| 145 | - return []; | |
| 123 | + protected function define_default_html_tag() { | |
| 124 | + return 'div'; | |
| 146 | 125 | } |
| 147 | 126 | |
| 148 | - private function get_children_dependencies_config(): array { | |
| 149 | - $config = []; | |
| 150 | - | |
| 151 | - foreach ( $this->define_children_dependencies() as $dependency ) { | |
| 152 | - if ( ! $dependency instanceof Child_Dependency ) { | |
| 153 | - throw new \InvalidArgumentException( | |
| 154 | - esc_html( static::class . '::define_children_dependencies() must return Child_Dependency instances.' ) | |
| 155 | - ); | |
| 156 | - } | |
| 157 | - | |
| 158 | - $config[] = $dependency->build(); | |
| 159 | - } | |
| 160 | - | |
| 161 | - return $config; | |
| 162 | - } | |
| 163 | - | |
| 164 | 127 | protected function define_initial_attributes() { |
| 165 | 128 | return []; |
| 166 | 129 | } |
| 167 | 130 | |
| 168 | - protected function define_allowed_child_types() { | |
| 169 | - return []; | |
| 170 | - } | |
| 171 | - | |
| 172 | - protected function get_interaction_id() { | |
| 173 | - return $this->origin_id ?? $this->get_id(); | |
| 174 | - } | |
| 175 | - | |
| 176 | 131 | protected function add_render_attributes() { |
| 177 | 132 | parent::add_render_attributes(); |
| 178 | 133 | |
| 179 | - $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 | + } | |
| 180 | 140 | } |
| 181 | 141 | |
| 182 | 142 | /** |
| 183 | 143 | * Get Element keywords. |
| @@ -203,9 +163,12 @@ | ||
| 203 | 163 | * |
| 204 | 164 | * @return string |
| 205 | 165 | */ |
| 206 | 166 | protected function get_html_tag(): string { |
| 207 | - return static::get_computed_html_tag( $this->get_atomic_settings() ); | |
| 167 | + $settings = $this->get_atomic_settings(); | |
| 168 | + $default_html_tag = $this->define_default_html_tag(); | |
| 169 | + | |
| 170 | + return ! empty( $settings['link']['href'] ) ? $settings['link']['tag'] : ( $settings['tag'] ?? $default_html_tag ); | |
| 208 | 171 | } |
| 209 | 172 | |
| 210 | 173 | /** |
| 211 | 174 | * Print safe HTML tag for the element based on the element settings. |
| @@ -224,13 +187,8 @@ | ||
| 224 | 187 | */ |
| 225 | 188 | protected function print_custom_attributes() { |
| 226 | 189 | $settings = $this->get_atomic_settings(); |
| 227 | 190 | $attributes = $settings['attributes'] ?? ''; |
| 228 | - | |
| 229 | - if ( isset( $settings['link']['attributes'] ) ) { | |
| 230 | - $attributes .= ' ' . ( $settings['link']['attributes'] ?? '' ); | |
| 231 | - } | |
| 232 | - | |
| 233 | 191 | if ( ! empty( $attributes ) && is_string( $attributes ) ) { |
| 234 | 192 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 235 | 193 | echo ' ' . $attributes; |
| 236 | 194 | } |