| @@ -2,21 +2,10 @@ | ||
| 2 | 2 | namespace Elementor\Modules\Components; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Core\Base\Module as BaseModule; |
| 5 | 5 | use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 6 | -use Elementor\Modules\AtomicWidgets\Module as AtomicWidgetsModule; | |
| 7 | -use Elementor\Plugin; | |
| 8 | -use Elementor\Modules\AtomicWidgets\PropsResolver\Transformers_Registry; | |
| 9 | 6 | use Elementor\Modules\Components\Styles\Component_Styles; |
| 10 | 7 | use Elementor\Modules\Components\Documents\Component as Component_Document; |
| 11 | -use Elementor\Modules\Components\Component_Lock_Manager; | |
| 12 | -use Elementor\Modules\Components\PropTypes\Component_Instance_Prop_Type; | |
| 13 | -use Elementor\Modules\Components\Transformers\Component_Instance_Transformer; | |
| 14 | -use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; | |
| 15 | -use Elementor\Modules\Components\Transformers\Overridable_Transformer; | |
| 16 | -use Elementor\Core\Base\Document; | |
| 17 | -use Elementor\Modules\Components\PropTypes\Override_Prop_Type; | |
| 18 | -use Elementor\Modules\Components\Transformers\Override_Transformer; | |
| 19 | 8 | |
| 20 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 21 | 10 | exit; // Exit if accessed directly. |
| 22 | 11 | } |
| @@ -31,34 +20,15 @@ | ||
| 31 | 20 | |
| 32 | 21 | public function __construct() { |
| 33 | 22 | parent::__construct(); |
| 34 | 23 | |
| 35 | - if ( ! $this->is_experiment_active() ) { | |
| 36 | - return; | |
| 37 | - } | |
| 38 | - | |
| 39 | - $this->register_component_post_type(); | |
| 40 | - | |
| 41 | 24 | add_filter( 'elementor/editor/v2/packages', fn ( $packages ) => $this->add_packages( $packages ) ); |
| 42 | - add_filter( 'elementor/atomic-widgets/props-schema', fn ( $schema ) => $this->modify_props_schema( $schema ) ); | |
| 43 | 25 | add_action( 'elementor/documents/register', fn ( $documents_manager ) => $this->register_document_type( $documents_manager ) ); |
| 44 | - add_action( 'elementor/document/before_save', fn( Document $document, array $data ) => $this->validate_circular_dependencies( $document, $data ), 10, 2 ); | |
| 45 | - add_action( 'elementor/document/after_save', fn( Document $document, array $data ) => $this->set_component_overridable_props( $document, $data ), 10, 2 ); | |
| 46 | - add_filter( 'elementor/global_classes/additional_post_types', fn( $post_types ) => array_merge( $post_types, [ Component_Document::TYPE ] ) ); | |
| 47 | 26 | |
| 48 | - add_action( 'elementor/atomic-widgets/settings/transformers/register', fn ( $transformers ) => $this->register_settings_transformers( $transformers ) ); | |
| 49 | - add_action( 'elementor/document/after_migrate', fn( Document $document, array $data ) => $this->after_component_migrate( $document, $data ), 10, 2 ); | |
| 50 | - | |
| 51 | - ( Component_Lock_Manager::get_instance()->register_hooks() ); | |
| 52 | 27 | ( new Component_Styles() )->register_hooks(); |
| 53 | 28 | ( new Components_REST_API() )->register_hooks(); |
| 54 | 29 | } |
| 55 | 30 | |
| 56 | - public function is_experiment_active() { | |
| 57 | - return Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME ) | |
| 58 | - && Plugin::$instance->experiments->is_feature_active( AtomicWidgetsModule::EXPERIMENT_NAME ); | |
| 59 | - } | |
| 60 | - | |
| 61 | 31 | public static function get_experimental_data() { |
| 62 | 32 | return [ |
| 63 | 33 | 'name' => self::EXPERIMENT_NAME, |
| 64 | 34 | 'title' => esc_html__( 'Components', 'elementor' ), |
| @@ -63,16 +33,16 @@ | ||
| 63 | 33 | 'name' => self::EXPERIMENT_NAME, |
| 64 | 34 | 'title' => esc_html__( 'Components', 'elementor' ), |
| 65 | 35 | 'description' => esc_html__( 'Enable components.', 'elementor' ), |
| 66 | 36 | 'hidden' => true, |
| 67 | - 'default' => Experiments_Manager::STATE_ACTIVE, | |
| 68 | - 'release_status' => Experiments_Manager::RELEASE_STATUS_BETA, | |
| 37 | + 'default' => Experiments_Manager::STATE_INACTIVE, | |
| 38 | + 'release_status' => Experiments_Manager::RELEASE_STATUS_DEV, | |
| 69 | 39 | ]; |
| 70 | 40 | } |
| 71 | 41 | |
| 72 | 42 | public function get_widgets() { |
| 73 | 43 | return [ |
| 74 | - 'Component_Instance', | |
| 44 | + 'Component', | |
| 75 | 45 | ]; |
| 76 | 46 | } |
| 77 | 47 | |
| 78 | 48 | private function add_packages( $packages ) { |
| @@ -78,13 +48,14 @@ | ||
| 78 | 48 | private function add_packages( $packages ) { |
| 79 | 49 | return array_merge( $packages, self::PACKAGES ); |
| 80 | 50 | } |
| 81 | 51 | |
| 82 | - private function modify_props_schema( array $schema ) { | |
| 83 | - return Overridable_Schema_Extender::make()->get_extended_schema( $schema ); | |
| 84 | - } | |
| 52 | + private function register_document_type( $documents_manager ) { | |
| 53 | + $documents_manager->register_document_type( | |
| 54 | + Component_Document::TYPE, | |
| 55 | + Component_Document::get_class_full_name() | |
| 56 | + ); | |
| 85 | 57 | |
| 86 | - private function register_component_post_type() { | |
| 87 | 58 | register_post_type( Component_Document::TYPE, [ |
| 88 | 59 | 'label' => Component_Document::get_title(), |
| 89 | 60 | 'labels' => Component_Document::get_labels(), |
| 90 | 61 | 'public' => false, |
| @@ -89,68 +60,6 @@ | ||
| 89 | 60 | 'labels' => Component_Document::get_labels(), |
| 90 | 61 | 'public' => false, |
| 91 | 62 | 'supports' => Component_Document::get_supported_features(), |
| 92 | 63 | ] ); |
| 93 | - } | |
| 94 | - | |
| 95 | - private function register_document_type( $documents_manager ) { | |
| 96 | - $documents_manager->register_document_type( | |
| 97 | - Component_Document::TYPE, | |
| 98 | - Component_Document::get_class_full_name() | |
| 99 | - ); | |
| 100 | - } | |
| 101 | - | |
| 102 | - private function validate_circular_dependencies( Document $document, array $data ) { | |
| 103 | - if ( ! $document instanceof Component_Document ) { | |
| 104 | - return; | |
| 105 | - } | |
| 106 | - | |
| 107 | - if ( ! isset( $data['elements'] ) ) { | |
| 108 | - return; | |
| 109 | - } | |
| 110 | - | |
| 111 | - $component_id = $document->get_main_id(); | |
| 112 | - $elements = $data['elements']; | |
| 113 | - | |
| 114 | - $result = Circular_Dependency_Validator::make()->validate( $component_id, $elements ); | |
| 115 | - | |
| 116 | - if ( ! $result['success'] ) { | |
| 117 | - throw new \Exception( esc_html__( "Can't add this component - components that contain each other can't be nested.", 'elementor' ) ); | |
| 118 | - } | |
| 119 | - } | |
| 120 | - | |
| 121 | - private function set_component_overridable_props( Document $document, array $data ) { | |
| 122 | - if ( ! isset( $data['settings'] ) ) { | |
| 123 | - return; | |
| 124 | - } | |
| 125 | - if ( ( ! $document instanceof Component_Document ) || | |
| 126 | - ( ! isset( $data['settings']['overridable_props'] ) ) | |
| 127 | - ) { | |
| 128 | - return; | |
| 129 | - } | |
| 130 | - | |
| 131 | - if ( ! Components_Access_Controller::can_edit() ) { | |
| 132 | - throw new \Exception( esc_html__( 'You do not have permission to edit component source.', 'elementor' ) ); | |
| 133 | - } | |
| 134 | - | |
| 135 | - /* @var Component_Document $document */ | |
| 136 | - $result = $document->update_overridable_props( $data['settings']['overridable_props'] ); | |
| 137 | - | |
| 138 | - if ( ! $result->is_valid() ) { | |
| 139 | - throw new \Exception( esc_html( 'Settings validation failed for component overridable props: ' . $result->errors()->to_string() ) ); | |
| 140 | - } | |
| 141 | - } | |
| 142 | - | |
| 143 | - private function register_settings_transformers( Transformers_Registry $transformers ) { | |
| 144 | - $transformers->register( Component_Instance_Prop_Type::get_key(), new Component_Instance_Transformer() ); | |
| 145 | - $transformers->register( Overridable_Prop_Type::get_key(), new Overridable_Transformer() ); | |
| 146 | - $transformers->register( Override_Prop_Type::get_key(), new Override_Transformer() ); | |
| 147 | - } | |
| 148 | - | |
| 149 | - private function after_component_migrate( Document $document, array $data ) { | |
| 150 | - if ( ! $document instanceof Component_Document ) { | |
| 151 | - return; | |
| 152 | - } | |
| 153 | - | |
| 154 | - $document->align_overridable_props_with_elements(); | |
| 155 | 64 | } |
| 156 | 65 | } |