-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14235 from craftcms/feature/cms-1234-add-env-var-…
…support-to-sites-language-settings Feature/cms 1234 add env var support to sites language settings
- Loading branch information
Showing
14 changed files
with
226 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/migrations/m240129_150719_sites_language_amend_length.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace craft\migrations; | ||
|
||
use Craft; | ||
use craft\db\Migration; | ||
use craft\db\Table; | ||
|
||
/** | ||
* m240129_150719_sites_language_amend_length migration. | ||
*/ | ||
class m240129_150719_sites_language_amend_length extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeUp(): bool | ||
{ | ||
if (Craft::$app->getDb()->tableExists(Table::SITES)) { | ||
$this->alterColumn(Table::SITES, 'language', $this->string()->notNull()); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeDown(): bool | ||
{ | ||
echo "m240129_150719_sites_language_amend_length cannot be reverted.\n"; | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
* @property bool|string $enabled Enabled | ||
* @property string|null $baseUrl The site’s base URL | ||
* @property string $name The site’s name | ||
* @property string $language The site’s language | ||
* @author Pixel & Tonic, Inc. <[email protected]> | ||
* @since 3.0.0 | ||
*/ | ||
|
@@ -46,11 +47,6 @@ class Site extends Model | |
*/ | ||
public ?string $handle = null; | ||
|
||
/** | ||
* @var string|null Name | ||
*/ | ||
public ?string $language = null; | ||
|
||
/** | ||
* @var bool Primary site? | ||
*/ | ||
|
@@ -102,6 +98,13 @@ class Site extends Model | |
*/ | ||
private bool|string $_enabled = true; | ||
|
||
/** | ||
* @var string|null Language | ||
* @see getLanguage() | ||
* @see setLanguage() | ||
*/ | ||
private ?string $_language = null; | ||
|
||
/** | ||
* Returns the site’s name. | ||
* | ||
|
@@ -182,6 +185,29 @@ public function setEnabled(bool|string $name): void | |
$this->_enabled = $name; | ||
} | ||
|
||
/** | ||
* Returns the site’s language. | ||
* | ||
* @param bool $parse Whether to parse the language for an environment variable | ||
* @return string | ||
* @since 5.0.0 | ||
*/ | ||
public function getLanguage(bool $parse = true): string | ||
{ | ||
return ($parse ? App::parseEnv($this->_language) : $this->_language) ?? ''; | ||
} | ||
|
||
/** | ||
* Sets the site’s language. | ||
* | ||
* @param string $language | ||
* @since 5.0.0 | ||
*/ | ||
public function setLanguage(string $language): void | ||
{ | ||
$this->_language = $language; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
|
@@ -299,7 +325,7 @@ public function getConfig(): array | |
'siteGroup' => $this->getGroup()->uid, | ||
'name' => $this->_name, | ||
'handle' => $this->handle, | ||
'language' => $this->language, | ||
'language' => $this->getLanguage(false), | ||
'hasUrls' => $this->hasUrls, | ||
'baseUrl' => $this->_baseUrl ?: null, | ||
'sortOrder' => $this->sortOrder, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% set id = id ?? "languagemenu#{random()}" %} | ||
{% set value = value ?? null -%} | ||
{% set options = options ?? [] %} | ||
{% set appOnly = appOnly ?? false %} | ||
|
||
|
||
{% if includeEnvVars ?? false %} | ||
{% set options = options|merge(craft.cp.getLanguageEnvOptions(appOnly)) %} | ||
{% endif %} | ||
|
||
{% include '_includes/forms/selectize' with { | ||
includeEnvVars: false, | ||
} %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.