← All changes
|
modules/atomic-widgets/props-resolver/render-props-resolver.php
+2
-60
4.3.0
→
3.32.3
View file →
| @@ -1,15 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Elementor\Modules\AtomicWidgets\PropsResolver; |
| 4 | 4 | |
| 5 | -use Elementor\Modules\AtomicWidgets\DynamicTags\Dynamic_Prop_Type; | |
| 6 | 5 | use Elementor\Modules\AtomicWidgets\PropTypes\Base\Array_Prop_Type; |
| 7 | 6 | use Elementor\Modules\AtomicWidgets\PropTypes\Base\Object_Prop_Type; |
| 8 | 7 | use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type; |
| 9 | -use Elementor\Modules\AtomicWidgets\PropTypes\Html_Prop_Type; | |
| 10 | 8 | use Elementor\Modules\AtomicWidgets\PropTypes\Union_Prop_Type; |
| 11 | -use Elementor\Plugin; | |
| 12 | 9 | use Exception; |
| 13 | 10 | |
| 14 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | 12 | exit; // Exit if accessed directly. |
| @@ -24,9 +21,8 @@ | ||
| 24 | 21 | const TRANSFORM_DEPTH_LIMIT = 3; |
| 25 | 22 | |
| 26 | 23 | const CONTEXT_SETTINGS = 'settings'; |
| 27 | 24 | const CONTEXT_STYLES = 'styles'; |
| 28 | - const CONTEXT_PLAIN = 'plain'; | |
| 29 | 25 | |
| 30 | 26 | public static function for_styles(): self { |
| 31 | 27 | return static::instance( self::CONTEXT_STYLES ); |
| 32 | 28 | } |
| @@ -34,18 +30,8 @@ | ||
| 34 | 30 | public static function for_settings(): self { |
| 35 | 31 | return static::instance( self::CONTEXT_SETTINGS ); |
| 36 | 32 | } |
| 37 | 33 | |
| 38 | - public static function for_plain(): self { | |
| 39 | - return static::instance( self::CONTEXT_PLAIN ); | |
| 40 | - } | |
| 41 | - | |
| 42 | - public function resolve_value( $value, Prop_Type $prop_type ) { | |
| 43 | - $value = $this->get_validated_value( $prop_type, $value ); | |
| 44 | - | |
| 45 | - return $this->resolve_item( $value, null, $prop_type ); | |
| 46 | - } | |
| 47 | - | |
| 48 | 34 | public function resolve( array $schema, array $props ): array { |
| 49 | 35 | $resolved = []; |
| 50 | 36 | |
| 51 | 37 | foreach ( $schema as $key => $prop_type ) { |
| @@ -52,13 +38,10 @@ | ||
| 52 | 38 | if ( ! ( $prop_type instanceof Prop_Type ) ) { |
| 53 | 39 | continue; |
| 54 | 40 | } |
| 55 | 41 | |
| 56 | - $prop_value = $props[ $key ] ?? null; | |
| 57 | - $actual_value = $this->get_validated_value( $prop_type, $prop_value ); | |
| 58 | - | |
| 59 | 42 | $transformed = $this->resolve_item( |
| 60 | - $actual_value, | |
| 43 | + $props[ $key ] ?? $prop_type->get_default(), | |
| 61 | 44 | $key, |
| 62 | 45 | $prop_type |
| 63 | 46 | ); |
| 64 | 47 | |
| @@ -79,9 +62,9 @@ | ||
| 79 | 62 | return null; |
| 80 | 63 | } |
| 81 | 64 | |
| 82 | 65 | if ( ! $this->is_transformable( $value ) ) { |
| 83 | - return $this->sanitize_html_prop_value( $value, $prop_type ); | |
| 66 | + return $value; | |
| 84 | 67 | } |
| 85 | 68 | |
| 86 | 69 | if ( $depth >= self::TRANSFORM_DEPTH_LIMIT ) { |
| 87 | 70 | return null; |
| @@ -93,47 +76,6 @@ | ||
| 93 | 76 | |
| 94 | 77 | $transformed = $this->transform( $value, $key, $prop_type ); |
| 95 | 78 | |
| 96 | 79 | return $this->resolve_item( $transformed, $key, $prop_type, $depth + 1 ); |
| 97 | - } | |
| 98 | - | |
| 99 | - private function get_validated_value( Prop_Type $prop_type, $prop_value ) { | |
| 100 | - $default = $prop_type->get_default() ?? null; | |
| 101 | - | |
| 102 | - if ( null === $prop_value ) { | |
| 103 | - return $default; | |
| 104 | - } | |
| 105 | - | |
| 106 | - if ( ! Dynamic_Prop_Type::is_dynamic_prop_value( $prop_value ) ) { | |
| 107 | - return $prop_value; | |
| 108 | - } | |
| 109 | - | |
| 110 | - $tag_name = $prop_value['value']['name'] ?? null; | |
| 111 | - $tag = Plugin::$instance->dynamic_tags->get_tag_info( $tag_name ); | |
| 112 | - | |
| 113 | - return ! $tag ? $default : $prop_value; | |
| 114 | - } | |
| 115 | - | |
| 116 | - private function sanitize_html_prop_value( $value, Prop_Type $prop_type ) { | |
| 117 | - if ( ! is_string( $value ) || ! $this->requires_html_sanitization( $prop_type ) ) { | |
| 118 | - return $value; | |
| 119 | - } | |
| 120 | - | |
| 121 | - return Html_Prop_Type::sanitize_allowed_html( $value ); | |
| 122 | - } | |
| 123 | - | |
| 124 | - private function requires_html_sanitization( Prop_Type $prop_type ): bool { | |
| 125 | - if ( $prop_type instanceof Html_Prop_Type ) { | |
| 126 | - return true; | |
| 127 | - } | |
| 128 | - | |
| 129 | - if ( $prop_type instanceof Union_Prop_Type ) { | |
| 130 | - foreach ( $prop_type->get_prop_types() as $variant ) { | |
| 131 | - if ( $this->requires_html_sanitization( $variant ) ) { | |
| 132 | - return true; | |
| 133 | - } | |
| 134 | - } | |
| 135 | - } | |
| 136 | - | |
| 137 | - return false; | |
| 138 | 80 | } |
| 139 | 81 | } |