| @@ -15,11 +15,9 @@ | ||
| 15 | 15 | use Elementor\Modules\Components\Transformers\Overridable_Transformer; |
| 16 | 16 | use Elementor\Core\Base\Document; |
| 17 | 17 | use Elementor\Modules\Components\PropTypes\Override_Prop_Type; |
| 18 | 18 | use Elementor\Modules\Components\Transformers\Override_Transformer; |
| 19 | -use Elementor\Modules\Components\Variants\Component_Variant_Class_Collector; | |
| 20 | 19 | use Elementor\Modules\Components\Widgets\Component_Instance; |
| 21 | -use Elementor\Modules\Components\Schema\Overridable_LLM_Filter; | |
| 22 | 20 | |
| 23 | 21 | if ( ! defined( 'ABSPATH' ) ) { |
| 24 | 22 | exit; // Exit if accessed directly. |
| 25 | 23 | } |
| @@ -24,18 +22,11 @@ | ||
| 24 | 22 | exit; // Exit if accessed directly. |
| 25 | 23 | } |
| 26 | 24 | |
| 27 | 25 | class Module extends BaseModule { |
| 28 | - const EXPERIMENT_NAME = AtomicWidgetsModule::EXPERIMENT_NAME; | |
| 29 | - const EXPERIMENT_VARIANTS_NAME = 'e_component_variants'; | |
| 26 | + const EXPERIMENT_NAME = 'e_components'; | |
| 30 | 27 | const PACKAGES = [ 'editor-components' ]; |
| 31 | 28 | |
| 32 | - /** | |
| 33 | - * Variants meta must be persisted before `Global_Classes_Relations::on_document_save()` | |
| 34 | - * (default priority 10) reads it via the `extract_class_ids_from_post` filter. | |
| 35 | - */ | |
| 36 | - const SAVE_VARIANTS_PRIORITY = 9; | |
| 37 | - | |
| 38 | 29 | public function get_name() { |
| 39 | 30 | return 'components'; |
| 40 | 31 | } |
| 41 | 32 | |
| @@ -41,14 +32,12 @@ | ||
| 41 | 32 | |
| 42 | 33 | public function __construct() { |
| 43 | 34 | parent::__construct(); |
| 44 | 35 | |
| 45 | - if ( ! self::is_experiment_active() ) { | |
| 36 | + if ( ! $this->is_experiment_active() ) { | |
| 46 | 37 | return; |
| 47 | 38 | } |
| 48 | 39 | |
| 49 | - $this->register_variants_experiment(); | |
| 50 | - | |
| 51 | 40 | $this->register_component_post_type(); |
| 52 | 41 | |
| 53 | 42 | add_filter( 'elementor/editor/v2/packages', fn ( $packages ) => $this->add_packages( $packages ) ); |
| 54 | 43 | add_filter( 'elementor/atomic-widgets/props-schema', fn ( $schema ) => $this->modify_props_schema( $schema ) ); |
| @@ -54,18 +43,8 @@ | ||
| 54 | 43 | add_filter( 'elementor/atomic-widgets/props-schema', fn ( $schema ) => $this->modify_props_schema( $schema ) ); |
| 55 | 44 | add_action( 'elementor/documents/register', fn ( $documents_manager ) => $this->register_document_type( $documents_manager ) ); |
| 56 | 45 | add_action( 'elementor/document/before_save', fn( Document $document, array $data ) => $this->validate_circular_dependencies( $document, $data ), 10, 2 ); |
| 57 | 46 | add_action( 'elementor/document/after_save', fn( Document $document, array $data ) => $this->set_component_overridable_props( $document, $data ), 10, 2 ); |
| 58 | - | |
| 59 | - if ( self::is_variants_experiment_active() ) { | |
| 60 | - add_action( 'elementor/document/after_save', fn( Document $document, array $data ) => $this->set_component_variants( $document, $data ), self::SAVE_VARIANTS_PRIORITY, 2 ); | |
| 61 | - add_filter( | |
| 62 | - 'elementor/global_classes/extract_class_ids_from_post', | |
| 63 | - fn( array $ids, $post_id ) => $this->add_variant_class_ids( $ids, $post_id ), | |
| 64 | - 10, | |
| 65 | - 2 | |
| 66 | - ); | |
| 67 | - } | |
| 68 | 47 | add_filter( 'elementor/global_classes/additional_post_types', fn( $post_types ) => array_merge( $post_types, [ Component_Document::TYPE ] ) ); |
| 69 | 48 | add_filter( 'elementor/utils/find_element_recursive/inner_elements', fn( array $inner_elements, array $element_data ) => $this->get_inner_elements_for_search( $inner_elements, $element_data ), 10, 2 ); |
| 70 | 49 | |
| 71 | 50 | add_action( 'elementor/atomic-widgets/settings/transformers/register', fn ( $transformers ) => $this->register_settings_transformers( $transformers ) ); |
| @@ -70,42 +49,29 @@ | ||
| 70 | 49 | |
| 71 | 50 | add_action( 'elementor/atomic-widgets/settings/transformers/register', fn ( $transformers ) => $this->register_settings_transformers( $transformers ) ); |
| 72 | 51 | add_action( 'elementor/document/after_migrate', fn( Document $document, array $data ) => $this->after_component_migrate( $document, $data ), 10, 2 ); |
| 73 | 52 | |
| 74 | - add_filter( | |
| 75 | - 'elementor/atomic-widgets/llm-json-schema', | |
| 76 | - fn( array $schema ) => ( new Overridable_LLM_Filter() )->apply( $schema ) | |
| 77 | - ); | |
| 78 | - | |
| 79 | 53 | ( Component_Lock_Manager::get_instance()->register_hooks() ); |
| 80 | 54 | ( new Component_Styles() )->register_hooks(); |
| 81 | 55 | ( new Components_REST_API() )->register_hooks(); |
| 82 | 56 | } |
| 83 | 57 | |
| 84 | - public static function is_experiment_active() { | |
| 85 | - return Plugin::$instance->experiments->is_feature_active( AtomicWidgetsModule::EXPERIMENT_NAME ); | |
| 58 | + public function is_experiment_active() { | |
| 59 | + return Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME ) | |
| 60 | + && Plugin::$instance->experiments->is_feature_active( AtomicWidgetsModule::EXPERIMENT_NAME ); | |
| 86 | 61 | } |
| 87 | 62 | |
| 88 | - public static function is_variants_experiment_active(): bool { | |
| 89 | - return Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_VARIANTS_NAME ); | |
| 63 | + public static function get_experimental_data() { | |
| 64 | + return [ | |
| 65 | + 'name' => self::EXPERIMENT_NAME, | |
| 66 | + 'title' => esc_html__( 'Components', 'elementor' ), | |
| 67 | + 'description' => esc_html__( 'Enable components.', 'elementor' ), | |
| 68 | + 'hidden' => true, | |
| 69 | + 'default' => Experiments_Manager::STATE_ACTIVE, | |
| 70 | + 'release_status' => Experiments_Manager::RELEASE_STATUS_BETA, | |
| 71 | + ]; | |
| 90 | 72 | } |
| 91 | 73 | |
| 92 | - /** | |
| 93 | - * Dev-only gate that keeps per-instance Component Variants off trunk while the feature ships | |
| 94 | - * across several tickets. Hidden experiments cannot declare dependencies on other experiments, | |
| 95 | - * so activation is checked manually in the constructor after the parent atomic-elements gate. | |
| 96 | - */ | |
| 97 | - private function register_variants_experiment() { | |
| 98 | - Plugin::$instance->experiments->add_feature( [ | |
| 99 | - 'name' => self::EXPERIMENT_VARIANTS_NAME, | |
| 100 | - 'title' => esc_html__( 'Component Variants', 'elementor' ), | |
| 101 | - 'description' => esc_html__( 'Enable per-instance class variants on components.', 'elementor' ), | |
| 102 | - 'hidden' => true, | |
| 103 | - 'default' => Experiments_Manager::STATE_INACTIVE, | |
| 104 | - 'release_status' => Experiments_Manager::RELEASE_STATUS_DEV, | |
| 105 | - ] ); | |
| 106 | - } | |
| 107 | - | |
| 108 | 74 | public function get_widgets() { |
| 109 | 75 | return [ |
| 110 | 76 | 'Component_Instance', |
| 111 | 77 | ]; |
| @@ -173,40 +139,8 @@ | ||
| 173 | 139 | |
| 174 | 140 | if ( ! $result->is_valid() ) { |
| 175 | 141 | throw new \Exception( esc_html( 'Settings validation failed for component overridable props: ' . $result->errors()->to_string() ) ); |
| 176 | 142 | } |
| 177 | - } | |
| 178 | - | |
| 179 | - private function set_component_variants( Document $document, array $data ) { | |
| 180 | - if ( ! isset( $data['settings'] ) ) { | |
| 181 | - return; | |
| 182 | - } | |
| 183 | - if ( ( ! $document instanceof Component_Document ) || | |
| 184 | - ( ! isset( $data['settings']['variants'] ) ) | |
| 185 | - ) { | |
| 186 | - return; | |
| 187 | - } | |
| 188 | - | |
| 189 | - if ( ! Components_Access_Controller::can_edit() ) { | |
| 190 | - throw new \Exception( esc_html__( 'You do not have permission to edit component source.', 'elementor' ) ); | |
| 191 | - } | |
| 192 | - | |
| 193 | - /* @var Component_Document $document */ | |
| 194 | - $result = $document->update_variants( $data['settings']['variants'] ); | |
| 195 | - | |
| 196 | - if ( ! $result->is_valid() ) { | |
| 197 | - throw new \Exception( esc_html( 'Settings validation failed for component variants: ' . $result->errors()->to_string() ) ); | |
| 198 | - } | |
| 199 | - } | |
| 200 | - | |
| 201 | - private function add_variant_class_ids( array $ids, $post_id ): array { | |
| 202 | - $document = Plugin::$instance->documents->get( (int) $post_id ); | |
| 203 | - | |
| 204 | - if ( ! $document instanceof Component_Document ) { | |
| 205 | - return $ids; | |
| 206 | - } | |
| 207 | - | |
| 208 | - return array_merge( $ids, Component_Variant_Class_Collector::collect( $document->get_variants() ) ); | |
| 209 | 143 | } |
| 210 | 144 | |
| 211 | 145 | private function register_settings_transformers( Transformers_Registry $transformers ) { |
| 212 | 146 | $transformers->register( Component_Instance_Prop_Type::get_key(), new Component_Instance_Transformer() ); |