Skip to content

Commit

Permalink
Closes #3863 Update Global Footer Links (#3871)
Browse files Browse the repository at this point in the history
Co-authored-by: Joe Parsons <[email protected]>
  • Loading branch information
bberndt-uaz and joeparsons committed Dec 6, 2024
1 parent 555ccf2 commit ca9549d
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 15 deletions.
107 changes: 107 additions & 0 deletions modules/custom/az_global_footer/az_global_footer.install
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]);
}
30 changes: 15 additions & 15 deletions modules/custom/az_global_footer/data/az_global_footer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit ca9549d

Please sign in to comment.