| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\ImportExport\Modifiers; |
| 4 |
|
| 5 |
use Elementor\Modules\AtomicWidgets\PropsResolver\Import_Export_Props_Resolver; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
class Interactions_Props_Modifier { |
| 12 |
private Import_Export_Props_Resolver $props_resolver; |
| 13 |
|
| 14 |
private array $schema; |
| 15 |
|
| 16 |
public function __construct( Import_Export_Props_Resolver $props_resolver, array $schema ) { |
| 17 |
$this->props_resolver = $props_resolver; |
| 18 |
$this->schema = $schema; |
| 19 |
} |
| 20 |
|
| 21 |
public static function make( Import_Export_Props_Resolver $props_resolver, array $schema ) { |
| 22 |
return new self( $props_resolver, $schema ); |
| 23 |
} |
| 24 |
|
| 25 |
public function run( array $element ) { |
| 26 |
if ( ! isset( $element['interactions'] ) ) { |
| 27 |
return $element; |
| 28 |
} |
| 29 |
|
| 30 |
$interactions = $element['interactions']; |
| 31 |
if ( is_string( $interactions ) ) { |
| 32 |
$decoded = json_decode( $interactions, true ); |
| 33 |
if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $decoded ) ) { |
| 34 |
return $element; |
| 35 |
} |
| 36 |
$interactions = $decoded; |
| 37 |
} |
| 38 |
|
| 39 |
if ( empty( $interactions['items'] ) || ! is_array( $interactions['items'] ) ) { |
| 40 |
return $element; |
| 41 |
} |
| 42 |
|
| 43 |
foreach ( $interactions['items'] as $index => $item ) { |
| 44 |
if ( ! is_array( $item ) || empty( $item['$$type'] ) || ! array_key_exists( 'value', $item ) || ! is_array( $item['value'] ) ) { |
| 45 |
continue; |
| 46 |
} |
| 47 |
|
| 48 |
$interactions['items'][ $index ]['value'] = $this->props_resolver->resolve( |
| 49 |
$this->schema, |
| 50 |
$item['value'] |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
$element['interactions'] = $interactions; |
| 55 |
|
| 56 |
return $element; |
| 57 |
} |
| 58 |
} |
| 59 |
|