From bf659d276147362ffdda7d1c3a83ea88064b5e6f Mon Sep 17 00:00:00 2001 From: Ahmet Bora Date: Tue, 10 Dec 2024 12:23:16 +0300 Subject: [PATCH] Hide language selector for single language #6850 --- src/Panel/Ui/Buttons/LanguagesDropdown.php | 3 ++- .../Ui/Buttons/LanguagesDropdownTest.php | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Panel/Ui/Buttons/LanguagesDropdown.php b/src/Panel/Ui/Buttons/LanguagesDropdown.php index 26d9775b35..9f0f8ffe91 100644 --- a/src/Panel/Ui/Buttons/LanguagesDropdown.php +++ b/src/Panel/Ui/Buttons/LanguagesDropdown.php @@ -111,7 +111,8 @@ public function props(): array public function render(): array|null { - if ($this->kirby->multilang() === false) { + // hides the language selector when there are less than 2 languages + if ($this->kirby->languages()->count() < 2) { return null; } diff --git a/tests/Panel/Ui/Buttons/LanguagesDropdownTest.php b/tests/Panel/Ui/Buttons/LanguagesDropdownTest.php index 5ebcc2a3fe..1771f15aa6 100644 --- a/tests/Panel/Ui/Buttons/LanguagesDropdownTest.php +++ b/tests/Panel/Ui/Buttons/LanguagesDropdownTest.php @@ -111,11 +111,32 @@ public function testProps() $this->assertFalse($props['hasChanges']); } + /** + * @covers ::render + */ + public function testRenderDefault() + { + $page = new Page(['slug' => 'test']); + $button = new LanguagesDropdown($page); + $this->assertNull($button->render()); + } + /** * @covers ::render */ public function testRenderSingleLang() { + $this->enableMultilang(); + $this->app([ + 'languages' => [ + 'en' => [ + 'code' => 'en', + 'default' => true, + 'name' => 'English' + ] + ] + ]); + $page = new Page(['slug' => 'test']); $button = new LanguagesDropdown($page); $this->assertNull($button->render());