elementor
/
modules
/
atomic-widgets
/
props-resolver
/
transformers
/
styles
/
transition-transformer.php
transition-transformer.php in Elementor Website Builder – more than just a page builder 3.35.0-dev1, at modules/atomic-widgets/props-resolver/transformers/styles/transition-transformer.php
| 1 | <?php |
| 2 | |
| 3 | namespace Elementor\Modules\AtomicWidgets\PropsResolver\Transformers\Styles; |
| 4 | |
| 5 | use Elementor\Modules\AtomicWidgets\PropsResolver\Props_Resolver_Context; |
| 6 | use Elementor\Modules\AtomicWidgets\PropsResolver\Transformer_Base; |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; // Exit if accessed directly. |
| 10 | } |
| 11 | |
| 12 | class Transition_Transformer extends Transformer_Base { |
| 13 | const EMPTY_STRING = ''; |
| 14 | |
| 15 | private function get_allowed_properties(): array { |
| 16 | $core_properties = [ 'all' ]; |
| 17 | |
| 18 | return apply_filters( |
| 19 | 'elementor/atomic-widgets/styles/transitions/allowed-properties', |
| 20 | $core_properties |
| 21 | ); |
| 22 | } |
| 23 | |
| 24 | public function transform( $transitions, Props_Resolver_Context $context ) { |
| 25 | if ( ! is_array( $transitions ) ) { |
| 26 | return self::EMPTY_STRING; |
| 27 | } |
| 28 | |
| 29 | $allowed_properties = $this->get_allowed_properties(); |
| 30 | |
| 31 | $transition_strings = array_map( |
| 32 | function( $transition ) use ( $allowed_properties ) { |
| 33 | return $this->map_to_transition_string( $transition, $allowed_properties ); |
| 34 | }, |
| 35 | $transitions |
| 36 | ); |
| 37 | |
| 38 | $valid_transitions = array_filter( $transition_strings ); |
| 39 | |
| 40 | return implode( ', ', $valid_transitions ); |
| 41 | } |
| 42 | |
| 43 | private function map_to_transition_string( $transition, array $allowed_properties ): string { |
| 44 | if ( empty( $transition['selection'] ) || empty( $transition['size'] ) ) { |
| 45 | return self::EMPTY_STRING; |
| 46 | } |
| 47 | |
| 48 | $selection = $transition['selection']; |
| 49 | $size = $transition['size']; |
| 50 | |
| 51 | if ( empty( $selection['value'] ) ) { |
| 52 | return self::EMPTY_STRING; |
| 53 | } |
| 54 | |
| 55 | $property = $selection['value']; |
| 56 | |
| 57 | if ( ! in_array( $property, $allowed_properties, true ) ) { |
| 58 | return self::EMPTY_STRING; |
| 59 | } |
| 60 | |
| 61 | return trim( "{$property} {$size}" ); |
| 62 | } |
| 63 | } |
| 64 |