PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.8
Elementor Website Builder – more than just a page builder v3.35.8
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 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | modules/atomic-widgets/elements/base/has-atomic-base.php +163 -210 4.3.0-beta33.35.8 View file →
@@ -4,11 +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 -use Elementor\Modules\AtomicWidgets\Logger\Logger;
11 8 use Elementor\Modules\AtomicWidgets\PropsResolver\Render_Props_Resolver;
12 9 use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type;
13 10 use Elementor\Modules\AtomicWidgets\Styles\Style_Schema;
14 11 use Elementor\Modules\AtomicWidgets\Parsers\Props_Parser;
@@ -16,9 +13,8 @@
16 13 use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
17 14 use Elementor\Modules\AtomicWidgets\PropTypes\Key_Value_Prop_Type;
18 15 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
19 16 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
20 -use Elementor\Modules\AtomicWidgets\PropTypes\Prop_Duplication_Behavior;
21 17 use Elementor\Utils;
22 18 use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
23 19 use Elementor\Modules\AtomicWidgets\Styles\Atomic_Widget_Styles;
24 20
@@ -30,20 +26,9 @@
30 26 * @mixin Element_Base
31 27 */
32 28 trait Has_Atomic_Base {
33 29 use Has_Base_Styles;
34 - use Has_Base_Settings;
35 30
36 - public static function html_tag_follows_link(): bool {
37 - return true;
38 - }
39 -
40 - public static function get_computed_html_tag( array $settings ): string {
41 - return Html_Tag_Computer::compute( $settings, 'div', [
42 - Html_Tag_Computer::FOLLOW_LINK_OPTION => static::html_tag_follows_link(),
43 - ] );
44 - }
45 -
46 31 public function has_widget_inner_wrapper(): bool {
47 32 return false;
48 33 }
49 34
@@ -100,74 +85,23 @@
100 85
101 86 private function parse_atomic_styles( array $data ): array {
102 87 $styles = $data['styles'] ?? [];
103 88 $style_parser = Style_Parser::make( Style_Schema::get() );
104 - $validated_styles = [];
105 89
106 90 foreach ( $styles as $style_id => $style ) {
107 91 $result = $style_parser->parse( $style );
108 92
109 93 if ( ! $result->is_valid() ) {
110 - Logger::warning(
111 - $this->format_styles_validation_error_message(
112 - $style_id,
113 - $data,
114 - $style,
115 - $result->errors()->to_string()
116 - )
117 - );
118 - continue;
94 + $widget_id = $data['id'] ?? 'unknown';
95 + throw new \Exception( esc_html( "Styles validation failed for style `$style_id`. Widget ID: `$widget_id`. " . $result->errors()->to_string() ) );
119 96 }
120 97
121 - $validated_styles[ $style_id ] = $result->unwrap();
98 + $styles[ $style_id ] = $result->unwrap();
122 99 }
123 100
124 - return $validated_styles;
101 + return $styles;
125 102 }
126 103
127 - private function format_styles_validation_error_message(
128 - string $style_id,
129 - array $data,
130 - array $style,
131 - string $validation_errors
132 - ): string {
133 - $widget_id = $data['id'] ?? 'unknown';
134 - $structure_label = $this->get_editor_structure_label( $data );
135 - $style_label = isset( $style['label'] ) && is_string( $style['label'] ) ? $style['label'] : null;
136 -
137 - $message_parts = [
138 - "Styles validation failed for style `$style_id` (widget `$widget_id`)",
139 - ];
140 -
141 - if ( $structure_label ) {
142 - $message_parts[] = "Structure label: `$structure_label`";
143 - } else {
144 - $element_name = $this->get_title();
145 -
146 - if ( '' === $element_name ) {
147 - $element_name = $this->get_name();
148 - }
149 -
150 - $message_parts[] = "Element: `$element_name`";
151 - }
152 -
153 - if ( $style_label ) {
154 - $message_parts[] = "Style label: `$style_label`";
155 - }
156 -
157 - return implode( '. ', $message_parts ) . '. ' . $validation_errors;
158 - }
159 -
160 - private function get_editor_structure_label( array $data ): ?string {
161 - $title = $data['editor_settings']['title'] ?? $this->editor_settings['title'] ?? null;
162 -
163 - if ( ! is_string( $title ) || '' === $title ) {
164 - return null;
165 - }
166 -
167 - return $title;
168 - }
169 -
170 104 private function parse_atomic_settings( array $settings ): array {
171 105 $schema = static::get_props_schema();
172 106 $props_parser = Props_Parser::make( $schema );
173 107
@@ -199,8 +133,67 @@
199 133
200 134 return [];
201 135 }
202 136
137 + private function convert_prop_type_interactions_to_legacy( $interactions ) {
138 + $legacy_items = [];
139 +
140 + foreach ( $interactions['items'] as $item ) {
141 + if ( isset( $item['$$type'] ) && 'interaction-item' === $item['$$type'] ) {
142 + $legacy_item = $this->extract_legacy_interaction_from_prop_type( $item );
143 + if ( $legacy_item ) {
144 + $legacy_items[] = $legacy_item;
145 + }
146 + } else {
147 + $legacy_items[] = $item;
148 + }
149 + }
150 +
151 + return [
152 + 'version' => $interactions['version'] ?? 1,
153 + 'items' => $legacy_items,
154 + ];
155 + }
156 +
157 + private function extract_legacy_interaction_from_prop_type( $item ) {
158 + if ( ! isset( $item['value'] ) || ! is_array( $item['value'] ) ) {
159 + return null;
160 + }
161 +
162 + $item_value = $item['value'];
163 +
164 + $interaction_id = $this->extract_prop_value( $item_value, 'interaction_id' );
165 + $trigger = $this->extract_prop_value( $item_value, 'trigger' );
166 + $animation = $this->extract_prop_value( $item_value, 'animation' );
167 +
168 + if ( ! is_array( $animation ) ) {
169 + return null;
170 + }
171 +
172 + $effect = $this->extract_prop_value( $animation, 'effect' );
173 + $type = $this->extract_prop_value( $animation, 'type' );
174 + $direction = $this->extract_prop_value( $animation, 'direction' );
175 + $timing_config = $this->extract_prop_value( $animation, 'timing_config' );
176 +
177 + $duration = 300;
178 + $delay = 0;
179 +
180 + if ( is_array( $timing_config ) ) {
181 + $duration = $this->extract_prop_value( $timing_config, 'duration', 300 );
182 + $delay = $this->extract_prop_value( $timing_config, 'delay', 0 );
183 + }
184 +
185 + $animation_id = implode( '-', [ $trigger, $effect, $type, $direction, $duration, $delay ] );
186 +
187 + return [
188 + 'interaction_id' => $interaction_id,
189 + 'animation' => [
190 + 'animation_id' => $animation_id,
191 + 'animation_type' => 'full-preset',
192 + ],
193 + ];
194 + }
195 +
203 196 private function extract_prop_value( $data, $key, $default = '' ) {
204 197 if ( ! is_array( $data ) || ! isset( $data[ $key ] ) ) {
205 198 return $default;
206 199 }
@@ -247,45 +240,20 @@
247 240 final public function get_data_for_save() {
248 241 $data = parent::get_data_for_save();
249 242
250 243 $data['version'] = $this->version;
244 + $data['settings'] = $this->parse_atomic_settings( $data['settings'] );
245 + $data['styles'] = $this->parse_atomic_styles( $data );
246 + $data['editor_settings'] = $this->parse_editor_settings( $data['editor_settings'] );
251 247
252 - $this->set_data_field_for_save(
253 - $data,
254 - 'settings',
255 - $this->parse_atomic_settings( $data['settings'] ?? [] )
256 - );
257 -
258 - $this->set_data_field_for_save(
259 - $data,
260 - 'styles',
261 - $this->parse_atomic_styles( $data )
262 - );
263 -
264 - $this->set_data_field_for_save(
265 - $data,
266 - 'editor_settings',
267 - $this->parse_editor_settings( $data['editor_settings'] ?? [] )
268 - );
269 -
270 - $this->set_data_field_for_save(
271 - $data,
272 - 'interactions',
273 - $this->transform_interactions_for_save( $data['interactions'] ?? [] )
274 - );
275 -
248 + if ( isset( $data['interactions'] ) && ! empty( $data['interactions'] ) ) {
249 + $data['interactions'] = $this->transform_interactions_for_save( $data['interactions'] );
250 + } else {
251 + $data['interactions'] = [];
252 + }
276 253 return $data;
277 254 }
278 255
279 - private function set_data_field_for_save( array &$data, string $key, $value ): void {
280 - if ( ! empty( $value ) ) {
281 - $data[ $key ] = $value;
282 - return;
283 - }
284 -
285 - unset( $data[ $key ] );
286 - }
287 -
288 256 private function transform_interactions_for_save( $interactions ) {
289 257 $decoded = $this->decode_interactions_data( $interactions );
290 258
291 259 if ( empty( $decoded['items'] ) ) {
@@ -331,31 +299,18 @@
331 299
332 300 public function get_atomic_settings(): array {
333 301 $schema = static::get_props_schema();
334 302 $props = $this->get_settings();
303 + $initial_attributes = $this->get_initial_attributes();
335 304
336 - $merged_attribute_values = array_merge(
337 - $this->get_initial_attributes()['value'] ?? [],
305 + $props['attributes'] = Attributes_Prop_Type::generate( array_merge(
306 + $initial_attributes['value'] ?? [],
338 307 $props['attributes']['value'] ?? []
339 - );
340 - $props['attributes'] = Attributes_Prop_Type::generate( $merged_attribute_values );
308 + ) );
341 309
342 - $parsed = Render_Props_Resolver::for_settings()->resolve( $schema, $props );
343 -
344 - return $this->transform_link_for_render( $parsed );
310 + return Render_Props_Resolver::for_settings()->resolve( $schema, $props );
345 311 }
346 312
347 - protected function transform_link_for_render( array $parsed ): array {
348 - $link_attributes = isset( $parsed['link'] ) ? $this->get_link_attributes_string( $parsed['link'] ) : '';
349 -
350 - $parsed['link'] = ! empty( $link_attributes ) ? [
351 - 'tag' => $parsed['link']['tag'],
352 - 'attributes' => $link_attributes,
353 - ] : null;
354 -
355 - return $parsed;
356 - }
357 -
358 313 protected function get_initial_attributes() {
359 314 return Attributes_Prop_Type::generate( [
360 315 Key_Value_Prop_Type::generate( [
361 316 'key' => String_Prop_Type::generate( 'data-e-type' ),
@@ -392,24 +347,15 @@
392 347 if ( isset( $data['title'] ) && is_string( $data['title'] ) ) {
393 348 $editor_data['title'] = sanitize_text_field( $data['title'] );
394 349 }
395 350
396 - if ( isset( $data['grid_outline'] ) && is_bool( $data['grid_outline'] ) ) {
397 - $editor_data['grid_outline'] = $data['grid_outline'];
398 - }
399 -
400 351 return $editor_data;
401 352 }
402 353
403 354 public static function get_props_schema(): array {
404 355 $schema = static::define_props_schema();
356 + $schema['_cssid'] = String_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() );
405 357
406 - if ( ! isset( $schema['_cssid'] ) ) {
407 - $schema['_cssid'] = String_Prop_Type::make()
408 - ->meta( Overridable_Prop_Type::ignore() )
409 - ->meta( Prop_Duplication_Behavior::clear() );
410 - }
411 -
412 358 return apply_filters(
413 359 'elementor/atomic-widgets/props-schema',
414 360 $schema
415 361 );
@@ -414,117 +360,124 @@
414 360 $schema
415 361 );
416 362 }
417 363
418 - protected function set_render_context( array $context_pairs ): void {
419 - foreach ( $context_pairs as $context_pair ) {
420 - $context_key = $context_pair['context_key'] ?? static::class;
421 - $context = $context_pair['context'];
422 - Render_Context::push( $context_key, $context );
364 + public function get_interactions_ids() {
365 + $animation_ids = [];
366 +
367 + $list_of_interactions = ( is_array( $this->interactions ) && isset( $this->interactions['items'] ) )
368 + ? $this->interactions['items']
369 + : [];
370 +
371 + foreach ( $list_of_interactions as $interaction ) {
372 + if ( isset( $interaction['$$type'] ) && 'interaction-item' === $interaction['$$type'] ) {
373 + $animation_id = $this->extract_animation_id_from_prop_type( $interaction );
374 + if ( $animation_id ) {
375 + $animation_ids[] = $animation_id;
376 + }
377 + } elseif ( isset( $interaction['animation']['animation_id'] ) ) {
378 + $animation_ids[] = $interaction['animation']['animation_id'];
379 + }
423 380 }
381 +
382 + return $animation_ids;
424 383 }
425 384
426 - protected function clear_render_context( array $context_pairs ): void {
427 - foreach ( $context_pairs as $context_pair ) {
428 - $context_key = $context_pair['context_key'] ?? static::class;
429 - Render_Context::pop( $context_key );
385 + private function extract_animation_id_from_prop_type( $item ) {
386 + if ( ! isset( $item['value'] ) || ! is_array( $item['value'] ) ) {
387 + return null;
430 388 }
389 +
390 + $item_value = $item['value'];
391 +
392 + $trigger = $this->extract_prop_value( $item_value, 'trigger' );
393 + $animation = $this->extract_prop_value( $item_value, 'animation' );
394 +
395 + if ( ! is_array( $animation ) ) {
396 + return null;
397 + }
398 +
399 + $effect = $this->extract_prop_value( $animation, 'effect' );
400 + $type = $this->extract_prop_value( $animation, 'type' );
401 + $direction = $this->extract_prop_value( $animation, 'direction' );
402 + $timing_config = $this->extract_prop_value( $animation, 'timing_config' );
403 + $config = $this->extract_prop_value( $animation, 'config' );
404 +
405 + $duration = 300;
406 + $delay = 0;
407 + $replay = 0;
408 + $relative_to = 'viewport';
409 + $offset_top = 15;
410 + $offset_bottom = 85;
411 +
412 + if ( is_array( $timing_config ) ) {
413 + $duration = $this->extract_prop_value( $timing_config, 'duration', 300 );
414 + $delay = $this->extract_prop_value( $timing_config, 'delay', 0 );
415 + }
416 +
417 + if ( is_array( $config ) ) {
418 + $relative_to = $this->extract_prop_value( $config, 'relative_to', 'viewport' );
419 + $offset_top = $this->extract_prop_value( $config, 'offset_top', 15 );
420 + $offset_bottom = $this->extract_prop_value( $config, 'offset_bottom', 85 );
421 +
422 + $replay = $this->extract_prop_value( $config, 'replay', 0 );
423 + if ( empty( $replay ) && 0 !== $replay && '0' !== $replay ) {
424 + $replay = 0;
425 + }
426 + } else {
427 + $replay = 0;
428 + }
429 +
430 + return implode( '-', [ $trigger, $effect, $type, $direction, $duration, $delay, $replay, $relative_to, $offset_top, $offset_bottom ] );
431 431 }
432 432
433 433 public function print_content() {
434 434 $defined_context = $this->define_render_context();
435 435
436 - if ( empty( $defined_context ) ) {
436 + $context_key = $defined_context['context_key'] ?? static::class;
437 + $element_context = $defined_context['context'] ?? [];
438 +
439 + $has_context = ! empty( $element_context );
440 +
441 + if ( ! $has_context ) {
437 442 return parent::print_content();
438 443 }
439 444
440 - $this->set_render_context( $defined_context );
445 + Render_Context::push( $context_key, $element_context );
441 446
442 447 parent::print_content();
443 448
444 - $this->clear_render_context( $defined_context );
449 + Render_Context::pop( $context_key );
445 450 }
446 451
447 452 /**
448 453 * Define the context for element's Render_Context.
449 454 *
450 - * @return array Array of context pairs. Each pair is an associative array with:
451 - * - 'context_key' (optional): The context key. Defaults to static::class if not provided.
452 - * - 'context' (required): The context value (can be any type).
453 - *
454 - * @example
455 - * [
456 - * [
457 - * 'context_key' => 'custom-key',
458 - * 'context' => ['some' => 'data'],
459 - * ],
460 - * [
461 - * 'context' => ['instance_id' => $this->get_id()],
462 - * ],
463 - * ]
455 + * @return array{context_key: ?string, context: array}
464 456 */
465 457 protected function define_render_context(): array {
466 - return [];
458 + return [
459 + 'context_key' => null,
460 + 'context' => [],
461 + ];
467 462 }
468 463
469 - protected function get_link_attributes( $link_settings ) {
470 - if ( empty( $link_settings['href'] ) ) {
471 - return [];
472 - }
473 -
464 + protected function get_link_attributes( $link_settings, $add_key_to_result = false ) {
474 465 $tag = $link_settings['tag'] ?? Link_Prop_Type::DEFAULT_TAG;
475 - $url = $link_settings['href'];
466 + $href = $link_settings['href'];
476 467 $target = $link_settings['target'] ?? '_self';
477 - $is_action_link = 'button' === $tag;
478 - $url_attr_key = $is_action_link ? 'data-action-link' : 'href';
479 468
480 - return [
481 - $url_attr_key => $url,
469 + $is_button = 'button' === $tag;
470 + $href_attribute_key = $is_button ? 'data-action-link' : 'href';
471 +
472 + $result = [
473 + $href_attribute_key => $href,
482 474 'target' => $target,
483 475 ];
484 - }
485 476
486 - private function get_link_attributes_string( $link_settings ) {
487 - $link_attributes = $this->get_link_attributes( $link_settings );
488 -
489 - if ( empty( $link_attributes ) ) {
490 - return '';
477 + if ( $add_key_to_result ) {
478 + $result['key'] = $href_attribute_key;
491 479 }
492 480
493 - $parts = [];
494 -
495 - foreach ( $link_attributes as $key => $value ) {
496 - if ( 'tag' === $key ) {
497 - continue;
498 - }
499 -
500 - $parts[] = sprintf( '%s="%s"', $key, esc_attr( $value ) );
501 - }
502 -
503 - return implode( ' ', $parts );
504 - }
505 -
506 - public function has_action_link() {
507 - if ( ! $this->get_id() ) {
508 - return true;
509 - }
510 -
511 - $link_settings = $this->get_atomic_setting( 'link' ) ?? null;
512 - $attributes = $this->get_link_attributes( $link_settings );
513 -
514 - return isset( $attributes['data-action-link'] );
515 - }
516 -
517 - public function get_script_depends() {
518 - $depends = parent::get_script_depends();
519 -
520 - if ( $this->has_action_link() ) {
521 - $depends[] = Frontend_Assets_Loader::ACTION_LINK_HANDLERS_HANDLE;
522 - }
523 -
524 - if ( Atomic_Form::is_instance_form( $this ) ) {
525 - $depends[] = Frontend_Assets_Loader::FORM_HANDLERS_HANDLE;
526 - }
527 -
528 - return $depends;
481 + return $result;
529 482 }
530 483 }