| @@ -2,9 +2,8 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Elementor\Modules\SiteNavigation; |
| 4 | 4 | |
| 5 | 5 | use Elementor\Core\Base\Module as Module_Base; |
| 6 | -use Elementor\Core\Experiments\Exceptions\Dependency_Exception; | |
| 7 | 6 | use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 8 | 7 | use Elementor\Modules\SiteNavigation\Data\Controller; |
| 9 | 8 | use Elementor\Modules\SiteNavigation\Rest_Fields\Page_User_Can; |
| 10 | 9 | use Elementor\Plugin; |
| @@ -11,40 +10,38 @@ | ||
| 11 | 10 | use Elementor\Utils; |
| 12 | 11 | |
| 13 | 12 | |
| 14 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | - exit; // Exit if accessed directly. | |
| 14 | + exit; // Exit if accessed directly | |
| 16 | 15 | } |
| 17 | 16 | |
| 18 | 17 | class Module extends Module_Base { |
| 19 | 18 | const PAGES_PANEL_EXPERIMENT_NAME = 'pages_panel'; |
| 20 | - const PACKAGES = [ | |
| 21 | - 'editor-site-navigation', | |
| 22 | - ]; | |
| 19 | + | |
| 23 | 20 | /** |
| 24 | 21 | * Initialize the Site navigation module. |
| 25 | - * | |
| 26 | 22 | * @return void |
| 27 | - * @throws \Exception If the experiment registration fails. | |
| 23 | + * @throws \Exception | |
| 28 | 24 | */ |
| 29 | 25 | public function __construct() { |
| 30 | 26 | Plugin::$instance->data_manager_v2->register_controller( new Controller() ); |
| 31 | 27 | |
| 28 | + $is_tests = Utils::is_elementor_tests(); | |
| 29 | + $is_v2_experiment_on = Plugin::$instance->experiments->is_feature_active( 'editor_v2' ); | |
| 30 | + if ( ! $is_v2_experiment_on && ! $is_tests ) { | |
| 31 | + return; | |
| 32 | + } | |
| 33 | + | |
| 32 | 34 | $this->register_pages_panel_experiment(); |
| 33 | 35 | |
| 34 | - add_filter( 'elementor/editor/v2/packages', fn( $packages ) => $this->add_packages( $packages ) ); | |
| 36 | + if ( Plugin::$instance->experiments->is_feature_active( self::PAGES_PANEL_EXPERIMENT_NAME ) ) { | |
| 37 | + add_filter( 'elementor/editor/v2/scripts/env', function( $env ) { | |
| 38 | + $env['@elementor/editor-site-navigation'] = [ | |
| 39 | + 'is_pages_panel_active' => true, | |
| 40 | + ]; | |
| 35 | 41 | |
| 36 | - add_filter( 'elementor/editor/v2/scripts/env', function( $env ) { | |
| 37 | - $env['@elementor/editor-site-navigation'] = [ | |
| 38 | - 'is_pages_panel_active' => Plugin::$instance->experiments->is_feature_active( | |
| 39 | - self::PAGES_PANEL_EXPERIMENT_NAME | |
| 40 | - ), | |
| 41 | - ]; | |
| 42 | - | |
| 43 | - return $env; | |
| 44 | - } ); | |
| 45 | - | |
| 46 | - if ( Plugin::$instance->experiments->is_feature_active( self::PAGES_PANEL_EXPERIMENT_NAME ) ) { | |
| 42 | + return $env; | |
| 43 | + } ); | |
| 47 | 44 | $this->register_rest_fields(); |
| 48 | 45 | } |
| 49 | 46 | } |
| 50 | 47 | |
| @@ -62,8 +59,9 @@ | ||
| 62 | 59 | * |
| 63 | 60 | * @since 3.16.0 |
| 64 | 61 | * |
| 65 | 62 | * @return void |
| 63 | + * @throws \Exception | |
| 66 | 64 | */ |
| 67 | 65 | private function register_pages_panel_experiment() { |
| 68 | 66 | Plugin::$instance->experiments->add_feature( [ |
| 69 | 67 | 'name' => self::PAGES_PANEL_EXPERIMENT_NAME, |
| @@ -70,8 +68,11 @@ | ||
| 70 | 68 | 'title' => esc_html__( 'Pages Panel', 'elementor' ), |
| 71 | 69 | 'release_status' => Experiments_Manager::RELEASE_STATUS_ALPHA, |
| 72 | 70 | 'default' => Experiments_Manager::STATE_INACTIVE, |
| 73 | 71 | 'hidden' => true, |
| 72 | + 'dependencies' => [ | |
| 73 | + 'editor_v2', | |
| 74 | + ], | |
| 74 | 75 | ] ); |
| 75 | 76 | } |
| 76 | 77 | |
| 77 | 78 | private function register_rest_fields() { |
| @@ -79,8 +80,5 @@ | ||
| 79 | 80 | ( new Page_User_Can() )->register_rest_field(); |
| 80 | 81 | } ); |
| 81 | 82 | } |
| 82 | 83 | |
| 83 | - private function add_packages( $packages ) { | |
| 84 | - return array_merge( $packages, self::PACKAGES ); | |
| 85 | - } | |
| 86 | 84 | } |