Skip to content

Commit

Permalink
Merge branch '4.14' of https://github.com/craftcms/cms into 5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jan 2, 2025
2 parents 73a1bc4 + 3db93e8 commit 7b14dd1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
- The `indexOf` Twig filter now has a `default` argument, which can be any integer or `null`. (`-1` by default for backwards compatibility.)
- It’s now possible to reference custom field handles in element queries’ `where` params. ([#16318](https://github.com/craftcms/cms/pull/16318))
- Number fields’ scalar values now return an integer if Decimals is set to `0`, and a number formatted with the correct decimal points when using MySQL. ([16369](https://github.com/craftcms/cms/issues/16369))
- Added support for specifying the current site via an `X-Craft-Site` header set to a site ID or handle. ([#16367](https://github.com/craftcms/cms/pull/16367))
- Deprecated the `ucfirst` Twig filter. `capitalize` should be used instead.

### Extensibility
Expand Down
1 change: 0 additions & 1 deletion src/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@
],
'sites' => [
'class' => craft\services\Sites::class,
'currentSite' => craft\helpers\App::env('CRAFT_SITE'),
],
'sso' => [
'class' => craft\services\Sso::class,
Expand Down
15 changes: 15 additions & 0 deletions src/web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use craft\helpers\StringHelper;
use craft\models\Site;
use craft\services\Sites;
use yii\base\InvalidArgumentException;
use yii\base\InvalidConfigException;
use yii\db\Exception as DbException;
use yii\di\Instance;
Expand Down Expand Up @@ -1542,6 +1543,20 @@ private function _requestedSite(?int &$siteScore = null): Site
return $site;
}

// Is CRAFT_SITE or X-Craft-Site present?
$siteId = App::env('CRAFT_SITE') ?? $this->getHeaders()->get('X-Craft-Site');
if ($siteId !== null) {
if (is_numeric($siteId)) {
$site = $this->sites->getSiteById($siteId, false);
} else {
$site = $this->sites->getSiteByHandle($siteId, false);
}
if (!$site && Craft::$app->getIsInstalled() && !Craft::$app->getUpdates()->getIsCraftUpdatePending()) {
throw new InvalidArgumentException("Invalid site: $siteId");
}
return $site;
}

$sites = $this->sites->getAllSites(false);

if (empty($sites)) {
Expand Down

0 comments on commit 7b14dd1

Please sign in to comment.