diff --git a/CHANGELOG.md b/CHANGELOG.md index 569e9ef7b36..d426f81b1aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ - Fixed a bug where row headings within Table fields weren’t getting statically translated in the control panel. ([#13703](https://github.com/craftcms/cms/discussions/13703)) - Fixed a bug where entry type chips within Matrix settings could be missing their action items. - Fixed a bug where custom field override settings’ Label, Handle, and Instructions fields could be missing their placeholder values. +- Fixed a bug where site name and language values set to environment variables were getting replaced with their resolved values when installing Craft. ([#18780](https://github.com/craftcms/cms/issues/18780)) +- Fixed a bug where site name values set to environment variables were getting replaced with their resolved values on save. ([#18789](https://github.com/craftcms/cms/pull/18789)) ## 5.9.22 - 2026-04-29 diff --git a/src/migrations/Install.php b/src/migrations/Install.php index 05422ea8732..45df94c401e 100644 --- a/src/migrations/Install.php +++ b/src/migrations/Install.php @@ -1184,7 +1184,7 @@ public function insertDefaultData(): void $site = $sitesService->getPrimarySite(); $site->setBaseUrl($this->site->getBaseUrl(false)); $site->hasUrls = $this->site->hasUrls; - $site->language = $this->site->language; + $site->language = $this->site->getLanguage(false); $site->setName($this->site->getName(false)); $sitesService->saveSite($site); } @@ -1322,7 +1322,7 @@ private function _generateInitialConfig(): array 'baseUrl' => $this->site->getBaseUrl(false), 'handle' => $this->site->handle, 'hasUrls' => $this->site->hasUrls, - 'language' => $this->site->language, + 'language' => $this->site->getLanguage(false), 'name' => $this->site->getName(false), 'primary' => true, 'siteGroup' => $siteGroupUid, diff --git a/src/models/Site.php b/src/models/Site.php index 4cf143eb43c..3730087b2d0 100644 --- a/src/models/Site.php +++ b/src/models/Site.php @@ -257,13 +257,29 @@ public function attributeLabels(): array ]; } + /** + * @inheritdoc + */ + public function beforeValidate(): bool + { + if (!parent::beforeValidate()) { + return false; + } + + // Can't use the `trim` rule because it replaces env vars + // see https://github.com/craftcms/cms/pull/18789 + $this->setName(trim($this->getName(false))); + + return true; + } + /** * @inheritdoc */ protected function defineRules(): array { $rules = parent::defineRules(); - $rules[] = [['name', 'handle'], 'trim']; + $rules[] = [['handle'], 'trim']; $rules[] = [['groupId', 'name', 'handle', 'language'], 'required']; $rules[] = [['id', 'groupId'], 'number', 'integerOnly' => true]; $rules[] = [['name', 'handle', 'baseUrl'], 'string', 'max' => 255];