From ca9549d8fd5e5cccb845c36594b7533c4a90e96a Mon Sep 17 00:00:00 2001 From: Brian Berndt <74572157+bberndt-uaz@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:51:30 -0700 Subject: [PATCH] Closes #3863 Update Global Footer Links (#3871) Co-authored-by: Joe Parsons <471936+joeparsons@users.noreply.github.com> --- .../az_global_footer/az_global_footer.install | 107 ++++++++++++++++++ .../data/az_global_footer.json | 30 ++--- 2 files changed, 122 insertions(+), 15 deletions(-) diff --git a/modules/custom/az_global_footer/az_global_footer.install b/modules/custom/az_global_footer/az_global_footer.install index f1918037b8..64cf806dcc 100644 --- a/modules/custom/az_global_footer/az_global_footer.install +++ b/modules/custom/az_global_footer/az_global_footer.install @@ -221,3 +221,110 @@ function az_global_footer_update_1020901() { return t('Updated %count UAlert menu link(s) in the global footer.', ['%count' => $updated_count]); } + +/** + * Make three updates to global footer links (az_quickstart #3863). + */ +function az_global_footer_update_1021101() { + + // Update the URL for the Annual Security Report link. + $asr_updates = 0; + $menu_link_content_ids = \Drupal::entityQuery('menu_link_content') + ->accessCheck(FALSE) + ->condition('menu_name', 'az-footer-main') + ->condition('title', 'Annual Security Report') + ->condition('link__uri', 'https://clery.arizona.edu/annual-reports') + ->execute(); + foreach ($menu_link_content_ids as $id) { + /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $menu_link_content */ + $menu_link_content = MenuLinkContent::load($id); + if ($menu_link_content !== NULL) { + /* @phpstan-ignore-next-line */ + $menu_link_content->link->uri = 'https://clery.arizona.edu/asr'; + $menu_link_content->save(); + $asr_updates++; + } + } + + // Delete the Outreach & Extension link and find the weight of the Athletics + // & Recreation link so the Campus Store link can be added directly below it. + // Also save the Campus Store link ID if it already exists. + $athletics_link_weight = NULL; + $outreach_link_ids = []; + $campus_store_link_id = NULL; + $topics_menu_ids = \Drupal::entityQuery('menu_link_content') + ->accessCheck(FALSE) + ->condition('menu_name', 'az-footer-topics') + ->execute(); + foreach ($topics_menu_ids as $id) { + /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $menu_link_content */ + $menu_link_content = MenuLinkContent::load($id); + if ($menu_link_content !== NULL) { + if ($menu_link_content->getTitle() === 'Outreach & Extension' && $menu_link_content->getUrlObject()->toString() === 'https://uaforyou.arizona.edu') { + $outreach_link_ids[] = $id; + $menu_link_content->delete(); + } + elseif ($menu_link_content->getTitle() === 'Athletics & Recreation' && $menu_link_content->getUrlObject()->toString() === 'https://www.arizona.edu/athletics-recreation' && $menu_link_content->isEnabled()) { + $athletics_link_weight = $menu_link_content->getWeight(); + } + elseif ($menu_link_content->getTitle() === 'Campus Store') { + $campus_store_link_id = $id; + } + } + } + + // Skip creating the Campus Store link if it already exists. + if (isset($campus_store_link_id)) { + return t('Updated %asr Annual Security Report menu link(s) in Footer - Main. Deleted %outreach Outreach & Extension menu link(s) in Footer - Topics. Campus Store link not created: link already exists in Footer - Topics.', + [ + '%asr' => $asr_updates, + '%outreach' => count($outreach_link_ids), + ]); + } + + // Skip creating the Campus Store link if Athletics & Recreation is missing. + if (!isset($athletics_link_weight)) { + return t('Updated %asr Annual Security Report menu link(s) in Footer - Main. Deleted %outreach Outreach & Extension menu link(s) in Footer - Topics. Campus Store link not created: no Athletics & Recreation link found in Footer - Topics.', + [ + '%asr' => $asr_updates, + '%outreach' => count($outreach_link_ids), + ]); + } + + // Remove the deleted Outreach & Extension link ID(s) for the next step. + if (!empty($outreach_link_ids)) { + foreach ($outreach_link_ids as $deleted_id) { + unset($topics_menu_ids[$deleted_id]); + } + } + + // Update the weights of links to create a space for the Campus Store link. + foreach ($topics_menu_ids as $id) { + /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $menu_link_content */ + $menu_link_content = MenuLinkContent::load($id); + if ($menu_link_content !== NULL) { + $weight = $menu_link_content->getWeight(); + if ($menu_link_content->getWeight() > $athletics_link_weight) { + $menu_link_content->set('weight', ++$weight); + $menu_link_content->save(); + } + } + } + + // Create the Campus Store link. + $menu_link = MenuLinkContent::create([ + 'title' => 'Campus Store', + 'link' => ['uri' => 'https://shop.arizona.edu/', 'title' => NULL], + 'menu_name' => 'az-footer-topics', + 'expanded' => FALSE, + 'external' => TRUE, + 'weight' => ++$athletics_link_weight, + ]); + $menu_link->save(); + + return t('Updated %asr Annual Security Report menu link(s) in Footer - Main. Deleted %outreach Outreach & Extension menu link(s) in Footer - Topics. Created 1 Campus Store link in Footer - Topics.', + [ + '%asr' => $asr_updates, + '%outreach' => count($outreach_link_ids), + ]); +} diff --git a/modules/custom/az_global_footer/data/az_global_footer.json b/modules/custom/az_global_footer/data/az_global_footer.json index 380cd03625..0d874345d0 100644 --- a/modules/custom/az_global_footer/data/az_global_footer.json +++ b/modules/custom/az_global_footer/data/az_global_footer.json @@ -49,7 +49,7 @@ "parent_link_id": "0", "menu": "az-footer-main", "title": "Annual Security Report", - "urlpath": "https://clery.arizona.edu/annual-reports", + "urlpath": "https://clery.arizona.edu/asr", "external": true, "expanded": false, "enabled": true, @@ -213,8 +213,8 @@ "link_id": "20", "parent_link_id": "0", "menu": "az-footer-topics", - "title": "Colleges, Schools, Departments", - "urlpath": "https://www.arizona.edu/colleges-schools", + "title": "Campus Store", + "urlpath": "https://shop.arizona.edu/", "external": true, "expanded": false, "enabled": true, @@ -224,8 +224,8 @@ "link_id": "21", "parent_link_id": "0", "menu": "az-footer-topics", - "title": "Diversity", - "urlpath": "https://diversity.arizona.edu", + "title": "Colleges, Schools, Departments", + "urlpath": "https://www.arizona.edu/colleges-schools", "external": true, "expanded": false, "enabled": true, @@ -235,8 +235,8 @@ "link_id": "22", "parent_link_id": "0", "menu": "az-footer-topics", - "title": "Environment & Sustainability", - "urlpath": "https://www.environment.arizona.edu", + "title": "Diversity", + "urlpath": "https://diversity.arizona.edu", "external": true, "expanded": false, "enabled": true, @@ -246,8 +246,8 @@ "link_id": "23", "parent_link_id": "0", "menu": "az-footer-topics", - "title": "International Engagement", - "urlpath": "https://international.arizona.edu", + "title": "Environment & Sustainability", + "urlpath": "https://www.environment.arizona.edu", "external": true, "expanded": false, "enabled": true, @@ -257,8 +257,8 @@ "link_id": "24", "parent_link_id": "0", "menu": "az-footer-topics", - "title": "Health & Medical", - "urlpath": "https://www.arizona.edu/health-sciences", + "title": "International Engagement", + "urlpath": "https://international.arizona.edu", "external": true, "expanded": false, "enabled": true, @@ -268,8 +268,8 @@ "link_id": "25", "parent_link_id": "0", "menu": "az-footer-topics", - "title": "Libraries", - "urlpath": "https://www.arizona.edu/libraries", + "title": "Health & Medical", + "urlpath": "https://www.arizona.edu/health-sciences", "external": true, "expanded": false, "enabled": true, @@ -279,8 +279,8 @@ "link_id": "26", "parent_link_id": "0", "menu": "az-footer-topics", - "title": "Outreach & Extension", - "urlpath": "https://uaforyou.arizona.edu", + "title": "Libraries", + "urlpath": "https://www.arizona.edu/libraries", "external": true, "expanded": false, "enabled": true,