PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.0-dev2
Elementor Website Builder – more than just a page builder v3.35.0-dev2
4.3.1 4.3.0 4.3.0-beta3 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 All 454 releases
← All changes | modules/atomic-widgets/elements/base/has-atomic-base.php +154 -156 4.2.0-beta2 → 3.35.0-dev2 View file →
@@ -4,10 +4,8 @@
4 4
5 5 use Elementor\Element_Base;
6 6 use Elementor\Modules\AtomicWidgets\Controls\Base\Atomic_Control_Base;
7 7 use Elementor\Modules\AtomicWidgets\Controls\Section;
8 -use Elementor\Modules\AtomicWidgets\Elements\Atomic_Form\Atomic_Form;
9 -use Elementor\Modules\AtomicWidgets\Elements\Loader\Frontend_Assets_Loader;
10 8 use Elementor\Modules\AtomicWidgets\PropsResolver\Render_Props_Resolver;
11 9 use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type;
12 10 use Elementor\Modules\AtomicWidgets\Styles\Style_Schema;
13 11 use Elementor\Modules\AtomicWidgets\Parsers\Props_Parser;
@@ -17,9 +15,8 @@
17 15 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
18 16 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
19 17 use Elementor\Utils;
20 18 use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
21 -use Elementor\Modules\AtomicWidgets\Styles\Atomic_Widget_Styles;
22 19
23 20 if ( ! defined( 'ABSPATH' ) ) {
24 21 exit; // Exit if accessed directly.
25 22 }
@@ -28,9 +25,8 @@
28 25 * @mixin Element_Base
29 26 */
30 27 trait Has_Atomic_Base {
31 28 use Has_Base_Styles;
32 - use Has_Base_Settings;
33 29
34 30 public function has_widget_inner_wrapper(): bool {
35 31 return false;
36 32 }
@@ -93,11 +89,10 @@
93 89 foreach ( $styles as $style_id => $style ) {
94 90 $result = $style_parser->parse( $style );
95 91
96 92 if ( ! $result->is_valid() ) {
97 - throw new \Exception(
98 - esc_html( $this->format_styles_validation_error_message( $style_id, $data, $style, $result->errors()->to_string() ) )
99 - );
93 + $widget_id = $data['id'] ?? 'unknown';
94 + throw new \Exception( esc_html( "Styles validation failed for style `$style_id`. Widget ID: `$widget_id`. " . $result->errors()->to_string() ) );
100 95 }
101 96
102 97 $styles[ $style_id ] = $result->unwrap();
103 98 }
@@ -104,51 +99,8 @@
104 99
105 100 return $styles;
106 101 }
107 102
108 - private function format_styles_validation_error_message(
109 - string $style_id,
110 - array $data,
111 - array $style,
112 - string $validation_errors
113 - ): string {
114 - $widget_id = $data['id'] ?? 'unknown';
115 - $structure_label = $this->get_editor_structure_label( $data );
116 - $style_label = isset( $style['label'] ) && is_string( $style['label'] ) ? $style['label'] : null;
117 -
118 - $message_parts = [
119 - "Styles validation failed for style `$style_id` (widget `$widget_id`)",
120 - ];
121 -
122 - if ( $structure_label ) {
123 - $message_parts[] = "Structure label: `$structure_label`";
124 - } else {
125 - $element_name = $this->get_title();
126 -
127 - if ( '' === $element_name ) {
128 - $element_name = $this->get_name();
129 - }
130 -
131 - $message_parts[] = "Element: `$element_name`";
132 - }
133 -
134 - if ( $style_label ) {
135 - $message_parts[] = "Style label: `$style_label`";
136 - }
137 -
138 - return implode( '. ', $message_parts ) . '. ' . $validation_errors;
139 - }
140 -
141 - private function get_editor_structure_label( array $data ): ?string {
142 - $title = $data['editor_settings']['title'] ?? $this->editor_settings['title'] ?? null;
143 -
144 - if ( ! is_string( $title ) || '' === $title ) {
145 - return null;
146 - }
147 -
148 - return $title;
149 - }
150 -
151 103 private function parse_atomic_settings( array $settings ): array {
152 104 $schema = static::get_props_schema();
153 105 $props_parser = Props_Parser::make( $schema );
154 106
@@ -180,8 +132,67 @@
180 132
181 133 return [];
182 134 }
183 135
136 + private function convert_prop_type_interactions_to_legacy( $interactions ) {
137 + $legacy_items = [];
138 +
139 + foreach ( $interactions['items'] as $item ) {
140 + if ( isset( $item['$$type'] ) && 'interaction-item' === $item['$$type'] ) {
141 + $legacy_item = $this->extract_legacy_interaction_from_prop_type( $item );
142 + if ( $legacy_item ) {
143 + $legacy_items[] = $legacy_item;
144 + }
145 + } else {
146 + $legacy_items[] = $item;
147 + }
148 + }
149 +
150 + return [
151 + 'version' => $interactions['version'] ?? 1,
152 + 'items' => $legacy_items,
153 + ];
154 + }
155 +
156 + private function extract_legacy_interaction_from_prop_type( $item ) {
157 + if ( ! isset( $item['value'] ) || ! is_array( $item['value'] ) ) {
158 + return null;
159 + }
160 +
161 + $item_value = $item['value'];
162 +
163 + $interaction_id = $this->extract_prop_value( $item_value, 'interaction_id' );
164 + $trigger = $this->extract_prop_value( $item_value, 'trigger' );
165 + $animation = $this->extract_prop_value( $item_value, 'animation' );
166 +
167 + if ( ! is_array( $animation ) ) {
168 + return null;
169 + }
170 +
171 + $effect = $this->extract_prop_value( $animation, 'effect' );
172 + $type = $this->extract_prop_value( $animation, 'type' );
173 + $direction = $this->extract_prop_value( $animation, 'direction' );
174 + $timing_config = $this->extract_prop_value( $animation, 'timing_config' );
175 +
176 + $duration = 300;
177 + $delay = 0;
178 +
179 + if ( is_array( $timing_config ) ) {
180 + $duration = $this->extract_prop_value( $timing_config, 'duration', 300 );
181 + $delay = $this->extract_prop_value( $timing_config, 'delay', 0 );
182 + }
183 +
184 + $animation_id = implode( '-', [ $trigger, $effect, $type, $direction, $duration, $delay ] );
185 +
186 + return [
187 + 'interaction_id' => $interaction_id,
188 + 'animation' => [
189 + 'animation_id' => $animation_id,
190 + 'animation_type' => 'full-preset',
191 + ],
192 + ];
193 + }
194 +
184 195 private function extract_prop_value( $data, $key, $default = '' ) {
185 196 if ( ! is_array( $data ) || ! isset( $data[ $key ] ) ) {
186 197 return $default;
187 198 }
@@ -270,9 +281,9 @@
270 281
271 282 final public function get_raw_data( $with_html_content = false ) {
272 283 $raw_data = parent::get_raw_data( $with_html_content );
273 284
274 - $raw_data['styles'] = Atomic_Widget_Styles::get_license_based_filtered_styles( $this->styles ?? [] );
285 + $raw_data['styles'] = $this->styles;
275 286 $raw_data['interactions'] = $this->interactions ?? [];
276 287 $raw_data['editor_settings'] = $this->editor_settings;
277 288
278 289 return $raw_data;
@@ -287,31 +298,18 @@
287 298
288 299 public function get_atomic_settings(): array {
289 300 $schema = static::get_props_schema();
290 301 $props = $this->get_settings();
302 + $initial_attributes = $this->get_initial_attributes();
291 303
292 - $merged_attribute_values = array_merge(
293 - $this->get_initial_attributes()['value'] ?? [],
304 + $props['attributes'] = Attributes_Prop_Type::generate( array_merge(
305 + $initial_attributes['value'] ?? [],
294 306 $props['attributes']['value'] ?? []
295 - );
296 - $props['attributes'] = Attributes_Prop_Type::generate( $merged_attribute_values );
307 + ) );
297 308
298 - $parsed = Render_Props_Resolver::for_settings()->resolve( $schema, $props );
299 -
300 - return $this->transform_link_for_render( $parsed );
309 + return Render_Props_Resolver::for_settings()->resolve( $schema, $props );
301 310 }
302 311
303 - protected function transform_link_for_render( array $parsed ): array {
304 - $link_attributes = isset( $parsed['link'] ) ? $this->get_link_attributes_string( $parsed['link'] ) : '';
305 -
306 - $parsed['link'] = ! empty( $link_attributes ) ? [
307 - 'tag' => $parsed['link']['tag'],
308 - 'attributes' => $link_attributes,
309 - ] : null;
310 -
311 - return $parsed;
312 - }
313 -
314 312 protected function get_initial_attributes() {
315 313 return Attributes_Prop_Type::generate( [
316 314 Key_Value_Prop_Type::generate( [
317 315 'key' => String_Prop_Type::generate( 'data-e-type' ),
@@ -348,22 +346,15 @@
348 346 if ( isset( $data['title'] ) && is_string( $data['title'] ) ) {
349 347 $editor_data['title'] = sanitize_text_field( $data['title'] );
350 348 }
351 349
352 - if ( isset( $data['grid_outline'] ) && is_bool( $data['grid_outline'] ) ) {
353 - $editor_data['grid_outline'] = $data['grid_outline'];
354 - }
355 -
356 350 return $editor_data;
357 351 }
358 352
359 353 public static function get_props_schema(): array {
360 354 $schema = static::define_props_schema();
355 + $schema['_cssid'] = String_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() );
361 356
362 - if ( ! isset( $schema['_cssid'] ) ) {
363 - $schema['_cssid'] = String_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() );
364 - }
365 -
366 357 return apply_filters(
367 358 'elementor/atomic-widgets/props-schema',
368 359 $schema
369 360 );
@@ -368,117 +359,124 @@
368 359 $schema
369 360 );
370 361 }
371 362
372 - protected function set_render_context( array $context_pairs ): void {
373 - foreach ( $context_pairs as $context_pair ) {
374 - $context_key = $context_pair['context_key'] ?? static::class;
375 - $context = $context_pair['context'];
376 - Render_Context::push( $context_key, $context );
363 + public function get_interactions_ids() {
364 + $animation_ids = [];
365 +
366 + $list_of_interactions = ( is_array( $this->interactions ) && isset( $this->interactions['items'] ) )
367 + ? $this->interactions['items']
368 + : [];
369 +
370 + foreach ( $list_of_interactions as $interaction ) {
371 + if ( isset( $interaction['$$type'] ) && 'interaction-item' === $interaction['$$type'] ) {
372 + $animation_id = $this->extract_animation_id_from_prop_type( $interaction );
373 + if ( $animation_id ) {
374 + $animation_ids[] = $animation_id;
375 + }
376 + } elseif ( isset( $interaction['animation']['animation_id'] ) ) {
377 + $animation_ids[] = $interaction['animation']['animation_id'];
378 + }
377 379 }
380 +
381 + return $animation_ids;
378 382 }
379 383
380 - protected function clear_render_context( array $context_pairs ): void {
381 - foreach ( $context_pairs as $context_pair ) {
382 - $context_key = $context_pair['context_key'] ?? static::class;
383 - Render_Context::pop( $context_key );
384 + private function extract_animation_id_from_prop_type( $item ) {
385 + if ( ! isset( $item['value'] ) || ! is_array( $item['value'] ) ) {
386 + return null;
384 387 }
388 +
389 + $item_value = $item['value'];
390 +
391 + $trigger = $this->extract_prop_value( $item_value, 'trigger' );
392 + $animation = $this->extract_prop_value( $item_value, 'animation' );
393 +
394 + if ( ! is_array( $animation ) ) {
395 + return null;
396 + }
397 +
398 + $effect = $this->extract_prop_value( $animation, 'effect' );
399 + $type = $this->extract_prop_value( $animation, 'type' );
400 + $direction = $this->extract_prop_value( $animation, 'direction' );
401 + $timing_config = $this->extract_prop_value( $animation, 'timing_config' );
402 + $config = $this->extract_prop_value( $animation, 'config' );
403 +
404 + $duration = 300;
405 + $delay = 0;
406 + $replay = 0;
407 + $relative_to = 'viewport';
408 + $offset_top = 15;
409 + $offset_bottom = 85;
410 +
411 + if ( is_array( $timing_config ) ) {
412 + $duration = $this->extract_prop_value( $timing_config, 'duration', 300 );
413 + $delay = $this->extract_prop_value( $timing_config, 'delay', 0 );
414 + }
415 +
416 + if ( is_array( $config ) ) {
417 + $relative_to = $this->extract_prop_value( $config, 'relative_to', 'viewport' );
418 + $offset_top = $this->extract_prop_value( $config, 'offset_top', 15 );
419 + $offset_bottom = $this->extract_prop_value( $config, 'offset_bottom', 85 );
420 +
421 + $replay = $this->extract_prop_value( $config, 'replay', 0 );
422 + if ( empty( $replay ) && 0 !== $replay && '0' !== $replay ) {
423 + $replay = 0;
424 + }
425 + } else {
426 + $replay = 0;
427 + }
428 +
429 + return implode( '-', [ $trigger, $effect, $type, $direction, $duration, $delay, $replay, $relative_to, $offset_top, $offset_bottom ] );
385 430 }
386 431
387 432 public function print_content() {
388 433 $defined_context = $this->define_render_context();
389 434
390 - if ( empty( $defined_context ) ) {
435 + $context_key = $defined_context['context_key'] ?? static::class;
436 + $element_context = $defined_context['context'] ?? [];
437 +
438 + $has_context = ! empty( $element_context );
439 +
440 + if ( ! $has_context ) {
391 441 return parent::print_content();
392 442 }
393 443
394 - $this->set_render_context( $defined_context );
444 + Render_Context::push( $context_key, $element_context );
395 445
396 446 parent::print_content();
397 447
398 - $this->clear_render_context( $defined_context );
448 + Render_Context::pop( $context_key );
399 449 }
400 450
401 451 /**
402 452 * Define the context for element's Render_Context.
403 453 *
404 - * @return array Array of context pairs. Each pair is an associative array with:
405 - * - 'context_key' (optional): The context key. Defaults to static::class if not provided.
406 - * - 'context' (required): The context value (can be any type).
407 - *
408 - * @example
409 - * [
410 - * [
411 - * 'context_key' => 'custom-key',
412 - * 'context' => ['some' => 'data'],
413 - * ],
414 - * [
415 - * 'context' => ['instance_id' => $this->get_id()],
416 - * ],
417 - * ]
454 + * @return array{context_key: ?string, context: array}
418 455 */
419 456 protected function define_render_context(): array {
420 - return [];
457 + return [
458 + 'context_key' => null,
459 + 'context' => [],
460 + ];
421 461 }
422 462
423 - protected function get_link_attributes( $link_settings ) {
424 - if ( empty( $link_settings['href'] ) ) {
425 - return [];
426 - }
427 -
463 + protected function get_link_attributes( $link_settings, $add_key_to_result = false ) {
428 464 $tag = $link_settings['tag'] ?? Link_Prop_Type::DEFAULT_TAG;
429 - $url = $link_settings['href'];
465 + $href = $link_settings['href'];
430 466 $target = $link_settings['target'] ?? '_self';
431 - $is_action_link = 'button' === $tag;
432 - $url_attr_key = $is_action_link ? 'data-action-link' : 'href';
433 467
434 - return [
435 - $url_attr_key => $url,
468 + $is_button = 'button' === $tag;
469 + $href_attribute_key = $is_button ? 'data-action-link' : 'href';
470 +
471 + $result = [
472 + $href_attribute_key => $href,
436 473 'target' => $target,
437 474 ];
438 - }
439 475
440 - private function get_link_attributes_string( $link_settings ) {
441 - $link_attributes = $this->get_link_attributes( $link_settings );
442 -
443 - if ( empty( $link_attributes ) ) {
444 - return '';
476 + if ( $add_key_to_result ) {
477 + $result['key'] = $href_attribute_key;
445 478 }
446 479
447 - $parts = [];
448 -
449 - foreach ( $link_attributes as $key => $value ) {
450 - if ( 'tag' === $key ) {
451 - continue;
452 - }
453 -
454 - $parts[] = sprintf( '%s="%s"', $key, esc_attr( $value ) );
455 - }
456 -
457 - return implode( ' ', $parts );
458 - }
459 -
460 - public function has_action_link() {
461 - if ( ! $this->get_id() ) {
462 - return true;
463 - }
464 -
465 - $link_settings = $this->get_atomic_setting( 'link' ) ?? null;
466 - $attributes = $this->get_link_attributes( $link_settings );
467 -
468 - return isset( $attributes['data-action-link'] );
469 - }
470 -
471 - public function get_script_depends() {
472 - $depends = parent::get_script_depends();
473 -
474 - if ( $this->has_action_link() ) {
475 - $depends[] = Frontend_Assets_Loader::ACTION_LINK_HANDLERS_HANDLE;
476 - }
477 -
478 - if ( Atomic_Form::is_instance_form( $this ) ) {
479 - $depends[] = Frontend_Assets_Loader::FORM_HANDLERS_HANDLE;
480 - }
481 -
482 - return $depends;
480 + return $result;
483 481 }
484 482 }