Skip to content

Commit

Permalink
Hide language selector for single language #6850
Browse files Browse the repository at this point in the history
  • Loading branch information
afbora committed Dec 10, 2024
1 parent 896c640 commit 85a2ec2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Panel/Ui/Buttons/LanguagesDropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
21 changes: 21 additions & 0 deletions tests/Panel/Ui/Buttons/LanguagesDropdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 85a2ec2

Please sign in to comment.