Skip to content

Commit

Permalink
Merge pull request #6858 from getkirby/fix/6853-allow-disable-all-pag…
Browse files Browse the repository at this point in the history
…e-buttons

Allow disable all page buttons via `buttons: false`
distantnative authored Dec 10, 2024
2 parents 9f5424d + 79612bf commit c8c7664
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Cms/Blueprint.php
Original file line number Diff line number Diff line change
@@ -217,7 +217,7 @@ protected function acceptedFileTemplatesFromFieldUploads(array $uploads): array
/**
* Gathers custom config for Panel view buttons
*/
public function buttons(): array|null
public function buttons(): array|false|null
{
return $this->props['buttons'] ?? null;
}
7 changes: 6 additions & 1 deletion src/Panel/Ui/Buttons/ViewButtons.php
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ class ViewButtons
{
public function __construct(
public readonly string $view,
public array|null $buttons = null,
public array|false|null $buttons = null,
public array $data = []
) {
$this->buttons ??= App::instance()->option(
@@ -57,6 +57,11 @@ public function defaults(string ...$defaults): static
*/
public function render(): array
{
// hides all buttons when `buttons: false` set
if ($this->buttons === false) {
return [];
}

$buttons = A::map(
$this->buttons ?? [],
fn ($button) =>
14 changes: 14 additions & 0 deletions tests/Cms/Blueprints/BlueprintTest.php
Original file line number Diff line number Diff line change
@@ -351,6 +351,20 @@ public function testButtons()
$this->assertSame(['foo', 'bar'], $blueprint->buttons());
}

/**
* @covers ::buttons
*/
public function testButtonsDisabled()
{
$blueprint = new Blueprint([
'model' => $this->model,
'name' => 'default',
'buttons' => false
]);

$this->assertSame(false, $blueprint->buttons());
}

/**
* @covers ::__debugInfo
*/
10 changes: 10 additions & 0 deletions tests/Panel/Ui/Buttons/ViewButtonsTest.php
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ public function setUp(): void
]
]);
}

/**
* @covers ::__construct
*/
@@ -103,6 +104,15 @@ public function testRenderFromConfig()
$this->assertSame('result-c', $result[2]['component']);
}

/**
* @covers ::render
*/
public function testRenderNoButtons()
{
$buttons = new ViewButtons('test', buttons: false);
$this->assertSame([], $buttons->render());
}

/**
* @covers ::view
*/

0 comments on commit c8c7664

Please sign in to comment.