From a9a1e07e76dd5cfe99f47aaee04c34bbcd0932c4 Mon Sep 17 00:00:00 2001
From: ebremner <ebremner@uwaterloo.ca>
Date: Tue, 1 Dec 2020 10:40:50 -0500
Subject: [PATCH] ISTWCMS-4199: using uwService to get the main menu

---
 uw_fdsu_theme_resp.theme | 63 +---------------------------------------
 1 file changed, 1 insertion(+), 62 deletions(-)

diff --git a/uw_fdsu_theme_resp.theme b/uw_fdsu_theme_resp.theme
index 9ef7494f..8faf1269 100644
--- a/uw_fdsu_theme_resp.theme
+++ b/uw_fdsu_theme_resp.theme
@@ -102,68 +102,7 @@ function uw_fdsu_theme_resp_preprocess_region(&$variables) {
   if ($region == "header") {
 
     // Get the main menu from the simplify menu module.
-    $main_menu = \Drupal::service('simplify_menu.menu_items')->getMenuTree('main');
-
-    // Set it to the menu_tree which is done by simplify menu.
-    $main_menu = $main_menu['menu_tree'];
-
-    // Step through the menu and do a few things:
-    // (a) Remove the Home link (this will be a house icon)
-    // (b) Add the number of menu items per menu link.
-    foreach ($main_menu as $index => $menu) {
-
-      // If this is the Home link, then remove it.
-      if ($menu['text'] == "Home") {
-
-        // Remove the home link.
-        unset($main_menu[$index]);
-      }
-
-      // If we are not on the home link, then add the number
-      // of menu items in this menu link.
-      else {
-
-        // Set the menu_item_count, initially to 0.
-        $menu_item_count = 0;
-
-        // If there is a submenu, recursivley call the count function.
-        if (isset($menu['submenu']) && count($menu['submenu']) > 0) {
-
-          // Call the count function recursively till we have the number of
-          // menu items.
-          _uw_fdsu_theme_resp_count_menu_items($menu, $menu_item_count);
-
-          // Now that we have a count of the number of menu items, we need to
-          // increment it by one as the main menu will also contain a link
-          // to the parent (itself) in the Tray.
-          // For example, the menu structure will look like:
-          // Parent (click box in the menu)
-          // Parent (link to the the Parent)
-          //   Child #1
-          //     Grandchild #1-1
-          //     Grandchild #1-2
-          //   Child #2
-          //   Child #3
-          //     Grandchild #3-1
-          //        Great grandchild #3-1-1
-          //        Great grandchild #3-1-2
-          //     Grandchild #3-2
-          //     Grandchild #3-3
-          //        Great grandchild #3-3-1
-          // So it should with the recursive function it will return 11,
-          // however as we are printing the parent again in the tray, we
-          // actually need 12, so hence the increase by1.
-          $main_menu[$index]['menu_items_count'] = $menu_item_count + 1;
-        }
-
-        // If there are no submenus, the count is 0, there will be no tray.
-        else {
-
-          // Set the number of items count, which is 0.
-          $main_menu[$index]['menu_items_count'] = $menu_item_count;
-        }
-      }
-    }
+    $main_menu = \Drupal::service('uw_cfg_common.uw_service')->uwGetMenu('main');
 
     // Set the main menu variable.
     $variables['main_menu'] = $main_menu;
-- 
GitLab