From 92cdb09fe32686eb1cf034ce495b2a54149a3db3 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 1 Jan 2025 17:56:20 -0800 Subject: [PATCH] primarySite global variable Resolves #16370 --- CHANGELOG-WIP.md | 1 + src/web/twig/Extension.php | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index 89f0f4f12d7..3e499a76e3a 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -7,6 +7,7 @@ - The Queue Manager utility now shows jobs’ class names. ([#16228](https://github.com/craftcms/cms/pull/16228)) ## Development +- Added the `primarySite` global Twig variable. ([#16370](https://github.com/craftcms/cms/discussions/16370)) - The `duration` Twig filter now has a `language` argument. ([#16332](https://github.com/craftcms/cms/pull/16332)) - Deprecated the `ucfirst` Twig filter. `capitalize` should be used instead. diff --git a/src/web/twig/Extension.php b/src/web/twig/Extension.php index 5e684f3199e..fa011ef40fe 100644 --- a/src/web/twig/Extension.php +++ b/src/web/twig/Extension.php @@ -1713,21 +1713,23 @@ public function getGlobals(): array $setPasswordRequestPath = $generalConfig->getSetPasswordRequestPath(); if ($isInstalled && !Craft::$app->getUpdates()->getIsCraftUpdatePending()) { - /** @noinspection PhpUnhandledExceptionInspection */ - $currentSite = Craft::$app->getSites()->getCurrentSite(); + $sitesService = Craft::$app->getSites(); + $currentSite = $sitesService->getCurrentSite(); + $primarySite = $sitesService->getPrimarySite(); $currentUser = Craft::$app->getUser()->getIdentity(); $siteName = Craft::t('site', $currentSite->getName()); $siteUrl = $currentSite->getBaseUrl(); $systemName = Craft::$app->getSystemName(); } else { - $currentSite = $currentUser = $siteName = $siteUrl = $systemName = null; + $currentSite = $primarySite = $currentUser = $siteName = $siteUrl = $systemName = null; } return [ 'craft' => new CraftVariable(), 'currentSite' => $currentSite, 'currentUser' => $currentUser, + 'primarySite' => $primarySite, 'siteName' => $siteName, 'siteUrl' => $siteUrl, 'systemName' => $systemName,