diff --git a/src/Sites/Site.php b/src/Sites/Site.php index 9e81178e7b1..75d4c777311 100644 --- a/src/Sites/Site.php +++ b/src/Sites/Site.php @@ -16,12 +16,14 @@ class Site implements Augmentable protected $handle; protected $config; protected $rawConfig; + protected $isDefault; - public function __construct($handle, $config) + public function __construct($handle, $config, $isDefault = false) { $this->handle = $handle; $this->config = $this->resolveAntlers($config); $this->rawConfig = $config; + $this->isDefault = $isDefault; } public function handle() @@ -95,6 +97,11 @@ public function relativePath($url) return $path === '' ? '/' : $path; } + public function isDefault() + { + return $this->isDefault; + } + public function set($key, $value) { $this->config[$key] = $this->resolveAntlersValue($value); diff --git a/src/Sites/Sites.php b/src/Sites/Sites.php index a93277ea66f..855f5786d5c 100644 --- a/src/Sites/Sites.php +++ b/src/Sites/Sites.php @@ -268,7 +268,9 @@ public function config(): array protected function hydrateConfig($config): Collection { - return collect($config)->map(fn ($site, $handle) => new Site($handle, $site)); + $defaultSiteHandle = collect($config)->keys()->first(); + + return collect($config)->map(fn ($site, $handle) => new Site($handle, $site, $handle === $defaultSiteHandle)); } protected function getNewSites(): Collection diff --git a/tests/Sites/SiteTest.php b/tests/Sites/SiteTest.php index a420833d49d..9dcdfe64aba 100644 --- a/tests/Sites/SiteTest.php +++ b/tests/Sites/SiteTest.php @@ -59,6 +59,16 @@ public function gets_lang() $this->assertEquals('en-US', (new Site('en', ['locale' => 'en-US', 'lang' => 'en-US']))->lang()); } + #[Test] + public function gets_is_default() + { + $withoutDefault = new Site('en', ['locale' => 'en_US']); + $withDefault = new Site('en', ['locale' => 'en_US'], true); + + $this->assertFalse($withoutDefault->isDefault()); + $this->assertTrue($withDefault->isDefault()); + } + #[Test] public function gets_url_when_given_a_trailing_slash() { diff --git a/tests/Sites/SitesConfigTest.php b/tests/Sites/SitesConfigTest.php index 27317f2440a..5419d31a2ad 100644 --- a/tests/Sites/SitesConfigTest.php +++ b/tests/Sites/SitesConfigTest.php @@ -54,12 +54,14 @@ public function it_gets_sites_from_yaml() $this->assertSame('/', Site::default()->url()); $this->assertSame('en_US', Site::default()->locale()); $this->assertSame('en', Site::default()->lang()); + $this->assertTrue(Site::default()->isDefault()); $this->assertSame('french', Site::get('french')->handle()); $this->assertSame('French', Site::get('french')->name()); $this->assertSame('/fr', Site::get('french')->url()); $this->assertSame('fr_FR', Site::get('french')->locale()); $this->assertSame('fr', Site::get('french')->lang()); + $this->assertFalse(Site::get('french')->isDefault()); } #[Test] @@ -78,6 +80,7 @@ public function it_gets_default_site_without_yaml() $this->assertSame('/', Site::default()->url()); $this->assertSame(config('app.locale'), Site::default()->locale()); $this->assertSame(config('app.locale'), Site::default()->lang()); + $this->assertTrue(Site::default()->isDefault()); } #[Test]