← All changes
|
modules/variables/classes/style-schema.php
+19
-37
4.2.0-dev2
→
3.29.0-beta4
View file →
| @@ -3,13 +3,11 @@ | ||
| 3 | 3 | namespace Elementor\Modules\Variables\Classes; |
| 4 | 4 | |
| 5 | 5 | use Elementor\Modules\AtomicWidgets\PropTypes\Base\Array_Prop_Type; |
| 6 | 6 | use Elementor\Modules\AtomicWidgets\PropTypes\Base\Object_Prop_Type; |
| 7 | -use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; | |
| 8 | 7 | use Elementor\Modules\AtomicWidgets\PropTypes\Color_Prop_Type; |
| 9 | 8 | use Elementor\Modules\AtomicWidgets\PropTypes\Union_Prop_Type; |
| 10 | -use Elementor\Modules\Variables\PropTypes\Color_Variable_Prop_Type; | |
| 11 | -use Elementor\Modules\Variables\PropTypes\Font_Variable_Prop_Type; | |
| 9 | +use Elementor\Modules\Variables\PropTypes\Color_Variable as Color_Variable_Prop_Type; | |
| 12 | 10 | |
| 13 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | 12 | exit; // Exit if accessed directly. |
| 15 | 13 | } |
| @@ -15,23 +13,15 @@ | ||
| 15 | 13 | } |
| 16 | 14 | |
| 17 | 15 | class Style_Schema { |
| 18 | 16 | public function augment( array $schema ): array { |
| 17 | + $result = []; | |
| 18 | + | |
| 19 | 19 | foreach ( $schema as $key => $prop_type ) { |
| 20 | - $schema[ $key ] = $this->update( $prop_type ); | |
| 21 | - if ( method_exists( $prop_type, 'get_meta' ) && method_exists( $schema[ $key ], 'meta' ) ) { | |
| 22 | - $meta = $schema[ $key ]->get_meta() ?? []; | |
| 23 | - foreach ( $meta as $meta_key => $meta_value ) { | |
| 24 | - $schema[ $key ]->meta( $meta_key, $meta_value ); | |
| 25 | - } | |
| 26 | - } | |
| 20 | + $result[ $key ] = $this->update( $prop_type ); | |
| 27 | 21 | } |
| 28 | 22 | |
| 29 | - if ( isset( $schema['font-family'] ) ) { | |
| 30 | - $schema['font-family'] = $this->update_font_family( $schema['font-family'] ); | |
| 31 | - } | |
| 32 | - | |
| 33 | - return $schema; | |
| 23 | + return $result; | |
| 34 | 24 | } |
| 35 | 25 | |
| 36 | 26 | private function update( $prop_type ) { |
| 37 | 27 | if ( $prop_type instanceof Color_Prop_Type ) { |
| @@ -52,49 +42,41 @@ | ||
| 52 | 42 | |
| 53 | 43 | return $prop_type; |
| 54 | 44 | } |
| 55 | 45 | |
| 56 | - private function update_font_family( $prop_type ): Union_Prop_Type { | |
| 57 | - | |
| 58 | - if ( $prop_type instanceof String_Prop_Type ) { | |
| 59 | - return Union_Prop_Type::create_from( $prop_type ) | |
| 60 | - ->add_prop_type( Font_Variable_Prop_Type::make() ); | |
| 61 | - } | |
| 62 | - | |
| 63 | - if ( $prop_type instanceof Union_Prop_Type ) { | |
| 64 | - $prop_type->add_prop_type( Font_Variable_Prop_Type::make() ); | |
| 65 | - } | |
| 66 | - | |
| 67 | - return $prop_type; | |
| 68 | - } | |
| 69 | - | |
| 70 | - private function update_color( Color_Prop_Type $color_prop_type ): Union_Prop_Type { | |
| 46 | + private function update_color( Color_Prop_Type $color_prop_type ) { | |
| 71 | 47 | return Union_Prop_Type::create_from( $color_prop_type ) |
| 72 | - ->add_prop_type( Color_Variable_Prop_Type::make() ); | |
| 48 | + ->add_prop_type( Color_Variable_Prop_Type::make() ); | |
| 73 | 49 | } |
| 74 | 50 | |
| 75 | - private function update_array( Array_Prop_Type $array_prop_type ): Array_Prop_Type { | |
| 51 | + private function update_array( Array_Prop_Type $array_prop_type ) { | |
| 76 | 52 | return $array_prop_type->set_item_type( |
| 77 | 53 | $this->update( $array_prop_type->get_item_type() ) |
| 78 | 54 | ); |
| 79 | 55 | } |
| 80 | 56 | |
| 81 | - private function update_object( Object_Prop_Type $object_prop_type ): Object_Prop_Type { | |
| 57 | + private function update_object( Object_Prop_Type $object_prop_type ) { | |
| 82 | 58 | return $object_prop_type->set_shape( |
| 83 | 59 | $this->augment( $object_prop_type->get_shape() ) |
| 84 | 60 | ); |
| 85 | 61 | } |
| 86 | 62 | |
| 87 | - private function update_union( Union_Prop_Type $union_prop_type ): Union_Prop_Type { | |
| 63 | + private function update_union( Union_Prop_Type $union_prop_type ) { | |
| 64 | + $new_union = Union_Prop_Type::make(); | |
| 65 | + | |
| 88 | 66 | foreach ( $union_prop_type->get_prop_types() as $prop_type ) { |
| 89 | 67 | $updated = $this->update( $prop_type ); |
| 90 | 68 | |
| 91 | 69 | if ( $updated instanceof Union_Prop_Type ) { |
| 92 | - foreach ( $updated->get_prop_types() as $updated_prop_type ) { | |
| 93 | - $union_prop_type->add_prop_type( $updated_prop_type ); | |
| 70 | + foreach ( $updated->get_prop_types() as $prop_type ) { | |
| 71 | + $new_union->add_prop_type( $prop_type ); | |
| 94 | 72 | } |
| 73 | + | |
| 74 | + continue; | |
| 95 | 75 | } |
| 76 | + | |
| 77 | + $new_union->add_prop_type( $updated ); | |
| 96 | 78 | } |
| 97 | 79 | |
| 98 | - return $union_prop_type; | |
| 80 | + return $new_union; | |
| 99 | 81 | } |
| 100 | 82 | } |