← All changes
|
modules/editor-one/classes/menu-data-provider.php
+26
-57
4.3.0-beta3
→
4.2.1
View file →
| @@ -4,9 +4,8 @@ | ||
| 4 | 4 | |
| 5 | 5 | use Elementor\Core\Admin\EditorOneMenu\Interfaces\Menu_Item_Interface; |
| 6 | 6 | use Elementor\Core\Admin\EditorOneMenu\Interfaces\Menu_Item_Third_Level_Interface; |
| 7 | 7 | use Elementor\Core\Admin\EditorOneMenu\Interfaces\Menu_Item_With_Custom_Url_Interface; |
| 8 | -use Elementor\Core\Admin\EditorOneMenu\Interfaces\Menu_Item_With_Event_Id_Interface; | |
| 9 | 8 | use Elementor\Plugin; |
| 10 | 9 | use Elementor\Utils; |
| 11 | 10 | |
| 12 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -24,9 +23,8 @@ | ||
| 24 | 23 | private ?array $cached_level3_sidebar_data = null; |
| 25 | 24 | private ?array $cached_level4_sidebar_data = null; |
| 26 | 25 | private ?array $cached_flyout_menu_data = null; |
| 27 | 26 | private Slug_Normalizer $slug_normalizer; |
| 28 | - private array $registration_options = []; | |
| 29 | 27 | |
| 30 | 28 | public static function instance(): self { |
| 31 | 29 | if ( null === self::$instance ) { |
| 32 | 30 | self::$instance = new self(); |
| @@ -42,13 +40,9 @@ | ||
| 42 | 40 | public function get_slug_normalizer(): Slug_Normalizer { |
| 43 | 41 | return $this->slug_normalizer; |
| 44 | 42 | } |
| 45 | 43 | |
| 46 | - public function register_menu( Menu_Item_Interface $item, array $options = [] ): void { | |
| 47 | - if ( ! empty( $options['preserve_label_casing'] ) ) { | |
| 48 | - $this->registration_options[ $item->get_slug() ]['preserve_label_casing'] = true; | |
| 49 | - } | |
| 50 | - | |
| 44 | + public function register_menu( Menu_Item_Interface $item ): void { | |
| 51 | 45 | if ( ! ( $item instanceof Menu_Item_Third_Level_Interface ) ) { |
| 52 | 46 | $this->register_level4_item( $item ); |
| 53 | 47 | return; |
| 54 | 48 | } |
| @@ -294,24 +288,37 @@ | ||
| 294 | 288 | } ) ); |
| 295 | 289 | } |
| 296 | 290 | |
| 297 | 291 | private function build_level3_flyout_items(): array { |
| 298 | - return $this->build_flyout_items( false, Menu_Config::get_excluded_level3_slugs() ); | |
| 292 | + return $this->build_flyout_items( false ); | |
| 299 | 293 | } |
| 300 | 294 | |
| 301 | 295 | private function build_flyout_items_with_expanded_third_party(): array { |
| 302 | - return $this->build_flyout_items( | |
| 303 | - true, | |
| 304 | - array_merge( | |
| 305 | - Menu_Config::get_excluded_level3_slugs(), | |
| 306 | - Menu_Config::get_excluded_flyout_menu_level3_slugs() | |
| 307 | - ) | |
| 308 | - ); | |
| 296 | + $items = $this->build_flyout_items( true ); | |
| 297 | + | |
| 298 | + if ( ! Utils::has_pro() ) { | |
| 299 | + $items[] = $this->build_theme_builder_flyout_item(); | |
| 300 | + } | |
| 301 | + | |
| 302 | + return $items; | |
| 309 | 303 | } |
| 310 | 304 | |
| 311 | - private function build_flyout_items( bool $expand_third_party, array $excluded_slugs ): array { | |
| 305 | + private function build_theme_builder_flyout_item(): array { | |
| 306 | + return [ | |
| 307 | + 'slug' => 'elementor-theme-builder', | |
| 308 | + 'label' => esc_html__( 'Theme Builder', 'elementor' ), | |
| 309 | + 'url' => $this->get_theme_builder_url(), | |
| 310 | + 'icon' => 'theme-builder', | |
| 311 | + 'group_id' => '', | |
| 312 | + 'priority' => 50, | |
| 313 | + 'has_divider_before' => false, | |
| 314 | + ]; | |
| 315 | + } | |
| 316 | + | |
| 317 | + private function build_flyout_items( bool $expand_third_party ): array { | |
| 312 | 318 | $items = []; |
| 313 | 319 | $existing_slugs = []; |
| 320 | + $excluded_slugs = Menu_Config::get_excluded_level3_slugs(); | |
| 314 | 321 | $excluded_level4_slugs = $expand_third_party ? Menu_Config::get_excluded_level4_slugs() : []; |
| 315 | 322 | |
| 316 | 323 | foreach ( $this->level3_items as $group_items ) { |
| 317 | 324 | foreach ( $group_items as $item_slug => $item ) { |
| @@ -370,14 +377,13 @@ | ||
| 370 | 377 | $url = $this->resolve_item_url( $item, $item_slug ); |
| 371 | 378 | |
| 372 | 379 | return [ |
| 373 | 380 | 'slug' => $item_slug, |
| 374 | - 'label' => $this->format_flyout_label( $item, $item_slug ), | |
| 381 | + 'label' => $this->title_case( $item->get_label() ), | |
| 375 | 382 | 'url' => $url, |
| 376 | 383 | 'group_id' => '', |
| 377 | 384 | 'priority' => $this->get_item_priority( $item ), |
| 378 | 385 | 'has_divider_before' => $is_first, |
| 379 | - 'event_id' => $this->resolve_event_id( $item, $item_slug ), | |
| 380 | 386 | ]; |
| 381 | 387 | } |
| 382 | 388 | |
| 383 | 389 | private function should_include_flyout_item( Menu_Item_Interface $item, string $item_slug, array $existing_slugs, array $excluded_slugs ): bool { |
| @@ -406,15 +412,14 @@ | ||
| 406 | 412 | $is_third_party_parent = Menu_Config::THIRD_PARTY_GROUP_ID === $item->get_group_id(); |
| 407 | 413 | |
| 408 | 414 | return [ |
| 409 | 415 | 'slug' => $item_slug, |
| 410 | - 'label' => $this->format_flyout_label( $item, $item_slug ), | |
| 416 | + 'label' => $this->title_case( $item->get_label() ), | |
| 411 | 417 | 'url' => $this->resolve_flyout_item_url( $item, $item_slug ), |
| 412 | 418 | 'icon' => $item->get_icon(), |
| 413 | 419 | 'group_id' => $group_id, |
| 414 | 420 | 'priority' => $this->get_item_priority( $item ), |
| 415 | 421 | 'has_divider_before' => $is_third_party_parent, |
| 416 | - 'event_id' => $this->resolve_event_id( $item, $item_slug ), | |
| 417 | 422 | ]; |
| 418 | 423 | } |
| 419 | 424 | |
| 420 | 425 | private function resolve_flyout_item_url( Menu_Item_Interface $item, string $item_slug ): string { |
| @@ -485,12 +490,11 @@ | ||
| 485 | 490 | $url = $this->resolve_item_url( $item, $item_slug ); |
| 486 | 491 | |
| 487 | 492 | $groups[ $group_id ]['items'][] = [ |
| 488 | 493 | 'slug' => $item_slug, |
| 489 | - 'label' => $this->format_flyout_label( $item, $item_slug ), | |
| 494 | + 'label' => $this->title_case( $item->get_label() ), | |
| 490 | 495 | 'url' => $url, |
| 491 | 496 | 'priority' => $this->get_item_priority( $item ), |
| 492 | - 'event_id' => $this->resolve_event_id( $item, $item_slug ), | |
| 493 | 497 | ]; |
| 494 | 498 | |
| 495 | 499 | $existing_labels[] = $label_lower; |
| 496 | 500 | } |
| @@ -546,43 +550,8 @@ | ||
| 546 | 550 | private function sort_items_by_priority( array &$items ): void { |
| 547 | 551 | usort( $items, function ( array $a, array $b ): int { |
| 548 | 552 | return ( $a['priority'] ?? 100 ) <=> ( $b['priority'] ?? 100 ); |
| 549 | 553 | } ); |
| 550 | - } | |
| 551 | - | |
| 552 | - private function resolve_event_id( Menu_Item_Interface $item, string $item_slug ): string { | |
| 553 | - if ( $item instanceof Menu_Item_With_Event_Id_Interface ) { | |
| 554 | - return $item->get_event_id(); | |
| 555 | - } | |
| 556 | - | |
| 557 | - return $this->derive_event_id_from_slug( $item_slug ); | |
| 558 | - } | |
| 559 | - | |
| 560 | - private function derive_event_id_from_slug( string $slug ): string { | |
| 561 | - $slug_event_map = [ | |
| 562 | - 'edit.php?post_type=elementor_library' => 'saved_templates', | |
| 563 | - 'elementor-app' => 'theme_builder', | |
| 564 | - ]; | |
| 565 | - | |
| 566 | - if ( isset( $slug_event_map[ $slug ] ) ) { | |
| 567 | - return $slug_event_map[ $slug ]; | |
| 568 | - } | |
| 569 | - | |
| 570 | - $event_id = preg_replace( '/^elementor-/', '', $slug ); | |
| 571 | - $event_id = preg_replace( '/[?#].*$/', '', $event_id ); | |
| 572 | - $event_id = str_replace( [ '-', ' ' ], '_', $event_id ); | |
| 573 | - | |
| 574 | - return strtolower( $event_id ); | |
| 575 | - } | |
| 576 | - | |
| 577 | - private function format_flyout_label( Menu_Item_Interface $item, string $item_slug ): string { | |
| 578 | - $label = $item->get_label(); | |
| 579 | - | |
| 580 | - if ( ! empty( $this->registration_options[ $item_slug ]['preserve_label_casing'] ) ) { | |
| 581 | - return $label; | |
| 582 | - } | |
| 583 | - | |
| 584 | - return $this->title_case( $label ); | |
| 585 | 554 | } |
| 586 | 555 | |
| 587 | 556 | private function title_case( string $text ): string { |
| 588 | 557 | if ( function_exists( 'mb_convert_case' ) ) { |