PluginProbe
Elementor Website Builder – more than just a page builder / 3.34.3
Elementor Website Builder – more than just a page builder v3.34.3
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 4.0.7 All 451 releases
elementor / modules / variables / classes / style-schema.php

style-schema.php in Elementor Website Builder – more than just a page builder 3.34.3, at modules/variables/classes/style-schema.php

92 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\Variables\Classes;
4
5 use Elementor\Modules\AtomicWidgets\PropTypes\Base\Array_Prop_Type;
6 use Elementor\Modules\AtomicWidgets\PropTypes\Base\Object_Prop_Type;
7 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
8 use Elementor\Modules\AtomicWidgets\PropTypes\Color_Prop_Type;
9 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;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 class Style_Schema {
18 public function augment( array $schema ): array {
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 }
27 }
28
29 if ( isset( $schema['font-family'] ) ) {
30 $schema['font-family'] = $this->update_font_family( $schema['font-family'] );
31 }
32
33 return $schema;
34 }
35
36 private function update( $prop_type ) {
37 if ( $prop_type instanceof Color_Prop_Type ) {
38 return $this->update_color( $prop_type );
39 }
40
41 if ( $prop_type instanceof Union_Prop_Type ) {
42 return $this->update_union( $prop_type );
43 }
44
45 if ( $prop_type instanceof Object_Prop_Type ) {
46 return $this->update_object( $prop_type );
47 }
48
49 if ( $prop_type instanceof Array_Prop_Type ) {
50 return $this->update_array( $prop_type );
51 }
52
53 return $prop_type;
54 }
55
56 private function update_font_family( String_Prop_Type $prop_type ): Union_Prop_Type {
57 return Union_Prop_Type::create_from( $prop_type )
58 ->add_prop_type( Font_Variable_Prop_Type::make() );
59 }
60
61 private function update_color( Color_Prop_Type $color_prop_type ): Union_Prop_Type {
62 return Union_Prop_Type::create_from( $color_prop_type )
63 ->add_prop_type( Color_Variable_Prop_Type::make() );
64 }
65
66 private function update_array( Array_Prop_Type $array_prop_type ): Array_Prop_Type {
67 return $array_prop_type->set_item_type(
68 $this->update( $array_prop_type->get_item_type() )
69 );
70 }
71
72 private function update_object( Object_Prop_Type $object_prop_type ): Object_Prop_Type {
73 return $object_prop_type->set_shape(
74 $this->augment( $object_prop_type->get_shape() )
75 );
76 }
77
78 private function update_union( Union_Prop_Type $union_prop_type ): Union_Prop_Type {
79 foreach ( $union_prop_type->get_prop_types() as $prop_type ) {
80 $updated = $this->update( $prop_type );
81
82 if ( $updated instanceof Union_Prop_Type ) {
83 foreach ( $updated->get_prop_types() as $updated_prop_type ) {
84 $union_prop_type->add_prop_type( $updated_prop_type );
85 }
86 }
87 }
88
89 return $union_prop_type;
90 }
91 }
92