PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.0
Elementor Website Builder – more than just a page builder v4.2.0
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 4.2.0, at modules/variables/classes/style-schema.php

101 lines 3.0 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( $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 {
71 return Union_Prop_Type::create_from( $color_prop_type )
72 ->add_prop_type( Color_Variable_Prop_Type::make() );
73 }
74
75 private function update_array( Array_Prop_Type $array_prop_type ): Array_Prop_Type {
76 return $array_prop_type->set_item_type(
77 $this->update( $array_prop_type->get_item_type() )
78 );
79 }
80
81 private function update_object( Object_Prop_Type $object_prop_type ): Object_Prop_Type {
82 return $object_prop_type->set_shape(
83 $this->augment( $object_prop_type->get_shape() )
84 );
85 }
86
87 private function update_union( Union_Prop_Type $union_prop_type ): Union_Prop_Type {
88 foreach ( $union_prop_type->get_prop_types() as $prop_type ) {
89 $updated = $this->update( $prop_type );
90
91 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 );
94 }
95 }
96 }
97
98 return $union_prop_type;
99 }
100 }
101