Skip to content

Commit

Permalink
primarySite global variable
Browse files Browse the repository at this point in the history
Resolves #16370
  • Loading branch information
brandonkelly committed Jan 2, 2025
1 parent 9791899 commit 92cdb09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
8 changes: 5 additions & 3 deletions src/web/twig/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 92cdb09

Please sign in to comment.