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 +151 -103 4.1.0-beta23.35.8 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;
@@ -135,8 +133,67 @@
135 133
136 134 return [];
137 135 }
138 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 +
139 196 private function extract_prop_value( $data, $key, $default = '' ) {
140 197 if ( ! is_array( $data ) || ! isset( $data[ $key ] ) ) {
141 198 return $default;
142 199 }
@@ -242,31 +299,18 @@
242 299
243 300 public function get_atomic_settings(): array {
244 301 $schema = static::get_props_schema();
245 302 $props = $this->get_settings();
303 + $initial_attributes = $this->get_initial_attributes();
246 304
247 - $merged_attribute_values = array_merge(
248 - $this->get_initial_attributes()['value'] ?? [],
305 + $props['attributes'] = Attributes_Prop_Type::generate( array_merge(
306 + $initial_attributes['value'] ?? [],
249 307 $props['attributes']['value'] ?? []
250 - );
251 - $props['attributes'] = Attributes_Prop_Type::generate( $merged_attribute_values );
308 + ) );
252 309
253 - $parsed = Render_Props_Resolver::for_settings()->resolve( $schema, $props );
254 -
255 - return $this->transform_link_for_render( $parsed );
310 + return Render_Props_Resolver::for_settings()->resolve( $schema, $props );
256 311 }
257 312
258 - protected function transform_link_for_render( array $parsed ): array {
259 - $link_attributes = isset( $parsed['link'] ) ? $this->get_link_attributes_string( $parsed['link'] ) : '';
260 -
261 - $parsed['link'] = ! empty( $link_attributes ) ? [
262 - 'tag' => $parsed['link']['tag'],
263 - 'attributes' => $link_attributes,
264 - ] : null;
265 -
266 - return $parsed;
267 - }
268 -
269 313 protected function get_initial_attributes() {
270 314 return Attributes_Prop_Type::generate( [
271 315 Key_Value_Prop_Type::generate( [
272 316 'key' => String_Prop_Type::generate( 'data-e-type' ),
@@ -308,13 +352,10 @@
308 352 }
309 353
310 354 public static function get_props_schema(): array {
311 355 $schema = static::define_props_schema();
356 + $schema['_cssid'] = String_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() );
312 357
313 - if ( ! isset( $schema['_cssid'] ) ) {
314 - $schema['_cssid'] = String_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() );
315 - }
316 -
317 358 return apply_filters(
318 359 'elementor/atomic-widgets/props-schema',
319 360 $schema
320 361 );
@@ -319,117 +360,124 @@
319 360 $schema
320 361 );
321 362 }
322 363
323 - protected function set_render_context( array $context_pairs ): void {
324 - foreach ( $context_pairs as $context_pair ) {
325 - $context_key = $context_pair['context_key'] ?? static::class;
326 - $context = $context_pair['context'];
327 - 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 + }
328 380 }
381 +
382 + return $animation_ids;
329 383 }
330 384
331 - protected function clear_render_context( array $context_pairs ): void {
332 - foreach ( $context_pairs as $context_pair ) {
333 - $context_key = $context_pair['context_key'] ?? static::class;
334 - 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;
335 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 ] );
336 431 }
337 432
338 433 public function print_content() {
339 434 $defined_context = $this->define_render_context();
340 435
341 - 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 ) {
342 442 return parent::print_content();
343 443 }
344 444
345 - $this->set_render_context( $defined_context );
445 + Render_Context::push( $context_key, $element_context );
346 446
347 447 parent::print_content();
348 448
349 - $this->clear_render_context( $defined_context );
449 + Render_Context::pop( $context_key );
350 450 }
351 451
352 452 /**
353 453 * Define the context for element's Render_Context.
354 454 *
355 - * @return array Array of context pairs. Each pair is an associative array with:
356 - * - 'context_key' (optional): The context key. Defaults to static::class if not provided.
357 - * - 'context' (required): The context value (can be any type).
358 - *
359 - * @example
360 - * [
361 - * [
362 - * 'context_key' => 'custom-key',
363 - * 'context' => ['some' => 'data'],
364 - * ],
365 - * [
366 - * 'context' => ['instance_id' => $this->get_id()],
367 - * ],
368 - * ]
455 + * @return array{context_key: ?string, context: array}
369 456 */
370 457 protected function define_render_context(): array {
371 - return [];
458 + return [
459 + 'context_key' => null,
460 + 'context' => [],
461 + ];
372 462 }
373 463
374 - protected function get_link_attributes( $link_settings ) {
375 - if ( empty( $link_settings['href'] ) ) {
376 - return [];
377 - }
378 -
464 + protected function get_link_attributes( $link_settings, $add_key_to_result = false ) {
379 465 $tag = $link_settings['tag'] ?? Link_Prop_Type::DEFAULT_TAG;
380 - $url = $link_settings['href'];
466 + $href = $link_settings['href'];
381 467 $target = $link_settings['target'] ?? '_self';
382 - $is_action_link = 'button' === $tag;
383 - $url_attr_key = $is_action_link ? 'data-action-link' : 'href';
384 468
385 - return [
386 - $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,
387 474 'target' => $target,
388 475 ];
389 - }
390 476
391 - private function get_link_attributes_string( $link_settings ) {
392 - $link_attributes = $this->get_link_attributes( $link_settings );
393 -
394 - if ( empty( $link_attributes ) ) {
395 - return '';
477 + if ( $add_key_to_result ) {
478 + $result['key'] = $href_attribute_key;
396 479 }
397 480
398 - $parts = [];
399 -
400 - foreach ( $link_attributes as $key => $value ) {
401 - if ( 'tag' === $key ) {
402 - continue;
403 - }
404 -
405 - $parts[] = sprintf( '%s="%s"', $key, esc_attr( $value ) );
406 - }
407 -
408 - return implode( ' ', $parts );
409 - }
410 -
411 - public function has_action_link() {
412 - if ( ! $this->get_id() ) {
413 - return true;
414 - }
415 -
416 - $link_settings = $this->get_atomic_setting( 'link' ) ?? null;
417 - $attributes = $this->get_link_attributes( $link_settings );
418 -
419 - return isset( $attributes['data-action-link'] );
420 - }
421 -
422 - public function get_script_depends() {
423 - $depends = parent::get_script_depends();
424 -
425 - if ( $this->has_action_link() ) {
426 - $depends[] = Frontend_Assets_Loader::ACTION_LINK_HANDLERS_HANDLE;
427 - }
428 -
429 - if ( Atomic_Form::is_instance_form( $this ) ) {
430 - $depends[] = Frontend_Assets_Loader::FORM_HANDLERS_HANDLE;
431 - }
432 -
433 - return $depends;
481 + return $result;
434 482 }
435 483 }