From a4e8f6996ce6efd804aa024b098f0e0c1e8eebde Mon Sep 17 00:00:00 2001 From: Paul Sealock Date: Thu, 8 Oct 2020 10:10:37 +1300 Subject: [PATCH] Navigation: Update PHP registration (https://github.com/woocommerce/woocommerce-admin/pull/5255) * UPdate to new registration API * conditionally add path to Overview * add comment * change to is_top_level --- .../src/Features/Analytics.php | 20 +++++++----- .../woocommerce-admin/src/PageController.php | 31 ++++++++++++------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/plugins/woocommerce-admin/src/Features/Analytics.php b/plugins/woocommerce-admin/src/Features/Analytics.php index e0823fa7a93..330e0f327f2 100644 --- a/plugins/woocommerce-admin/src/Features/Analytics.php +++ b/plugins/woocommerce-admin/src/Features/Analytics.php @@ -112,15 +112,19 @@ class Analytics { * Registers report pages. */ public function register_pages() { + $overview_page = array( + 'id' => 'woocommerce-analytics', + 'title' => __( 'Analytics', 'woocommerce-admin' ), + 'path' => '/analytics/overview', + 'icon' => 'dashicons-chart-bar', + 'position' => 56, // After WooCommerce & Product menu items. + ); + if ( class_exists( '\Automattic\WooCommerce\Navigation\Menu' ) ) { + unset( $overview_page['path'] ); + } + $report_pages = array( - array( - 'id' => 'woocommerce-analytics', - 'title' => __( 'Analytics', 'woocommerce-admin' ), - 'path' => '/analytics/overview', - 'path' => '/analytics/overview', - 'icon' => 'dashicons-chart-bar', - 'position' => 56, // After WooCommerce & Product menu items. - ), + $overview_page, array( 'id' => 'woocommerce-analytics-overview', 'title' => __( 'Overview', 'woocommerce-admin' ), diff --git a/plugins/woocommerce-admin/src/PageController.php b/plugins/woocommerce-admin/src/PageController.php index ba341c17384..e210d63d3f0 100644 --- a/plugins/woocommerce-admin/src/PageController.php +++ b/plugins/woocommerce-admin/src/PageController.php @@ -439,14 +439,19 @@ class PageController { ); if ( method_exists( '\Automattic\WooCommerce\Navigation\Menu', 'add_category' ) ) { - \Automattic\WooCommerce\Navigation\Menu::add_category( - array( - 'id' => $options['id'], - 'title' => $options['title'], - 'capability' => $options['capability'], - 'url' => $options['path'], - ) + $category_options = array( + 'id' => $options['id'], + 'title' => $options['title'], + 'capability' => $options['capability'], + 'url' => $options['path'], + 'is_top_level' => true, ); + + // If there is no path option, remove url because its a parent category item. + if ( 'wc-admin&path=' === $options['path'] ) { + unset( $category_options['url'] ); + } + \Automattic\WooCommerce\Navigation\Menu::add_category( $category_options ); } } else { $parent_path = $this->get_path_from_id( $options['parent'] ); @@ -461,13 +466,15 @@ class PageController { ); if ( method_exists( '\Automattic\WooCommerce\Navigation\Menu', 'add_item' ) ) { + $top_level_ids = array( 'woocommerce-home', 'woocommerce-analytics-customers' ); \Automattic\WooCommerce\Navigation\Menu::add_item( array( - 'id' => $options['id'], - 'parent' => $options['parent'], - 'title' => $options['title'], - 'capability' => $options['capability'], - 'url' => $options['path'], + 'id' => $options['id'], + 'parent' => $options['parent'], + 'title' => $options['title'], + 'capability' => $options['capability'], + 'url' => $options['path'], + 'is_top_level' => in_array( $options['id'], $top_level_ids, true ), ) ); }