| @@ -5,8 +5,10 @@ | ||
| 5 | 5 | use Elementor\Core\Utils\Api\Parse_Result; |
| 6 | 6 | use Elementor\Modules\Components\OverridableProps\Component_Overridable_Props_Parser; |
| 7 | 7 | use Elementor\Modules\Components\PropTypes\Override_Prop_Type; |
| 8 | 8 | use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; |
| 9 | +use Elementor\Modules\Components\Variants\Component_Variants; | |
| 10 | +use Elementor\Modules\Components\Variants\Component_Variants_Parser; | |
| 9 | 11 | use Elementor\Modules\Components\Widgets\Component_Instance; |
| 10 | 12 | |
| 11 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | 14 | exit; // Exit if accessed directly |
| @@ -15,13 +17,15 @@ | ||
| 15 | 17 | class Component extends Document { |
| 16 | 18 | const TYPE = 'elementor_component'; |
| 17 | 19 | const COMPONENT_UID_META_KEY = '_elementor_component_uid'; |
| 18 | 20 | const OVERRIDABLE_PROPS_META_KEY = '_elementor_component_overridable_props'; |
| 21 | + const VARIANTS_META_KEY = '_elementor_component_variants'; | |
| 19 | 22 | const ARCHIVED_META_KEY = '_elementor_component_is_archived'; |
| 20 | 23 | const ARCHIVED_AT_META_KEY = '_elementor_component_archived_at'; |
| 21 | 24 | const COMPONENT_CUSTOM_META_KEYS = [ |
| 22 | 25 | self::COMPONENT_UID_META_KEY, |
| 23 | 26 | self::OVERRIDABLE_PROPS_META_KEY, |
| 27 | + self::VARIANTS_META_KEY, | |
| 24 | 28 | self::ARCHIVED_META_KEY, |
| 25 | 29 | self::ARCHIVED_AT_META_KEY, |
| 26 | 30 | ]; |
| 27 | 31 | |
| @@ -106,8 +110,30 @@ | ||
| 106 | 110 | |
| 107 | 111 | $sanitized_data = $result->unwrap(); |
| 108 | 112 | |
| 109 | 113 | $this->update_json_meta( self::OVERRIDABLE_PROPS_META_KEY, $sanitized_data ); |
| 114 | + | |
| 115 | + return $result; | |
| 116 | + } | |
| 117 | + | |
| 118 | + public function get_variants(): Component_Variants { | |
| 119 | + $meta = $this->get_json_meta( self::VARIANTS_META_KEY ); | |
| 120 | + | |
| 121 | + return Component_Variants::make( $meta ?? [] ); | |
| 122 | + } | |
| 123 | + | |
| 124 | + public function update_variants( $data ): Parse_Result { | |
| 125 | + $parser = Component_Variants_Parser::make(); | |
| 126 | + | |
| 127 | + $result = $parser->parse( $data ); | |
| 128 | + | |
| 129 | + if ( ! $result->is_valid() ) { | |
| 130 | + return $result; | |
| 131 | + } | |
| 132 | + | |
| 133 | + $sanitized_data = $result->unwrap(); | |
| 134 | + | |
| 135 | + $this->update_json_meta( self::VARIANTS_META_KEY, $sanitized_data ); | |
| 110 | 136 | |
| 111 | 137 | return $result; |
| 112 | 138 | } |
| 113 | 139 | |