diff --git a/src/Cms/Blueprint.php b/src/Cms/Blueprint.php index f24c79d75f..6a620145db 100644 --- a/src/Cms/Blueprint.php +++ b/src/Cms/Blueprint.php @@ -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; } diff --git a/src/Panel/Ui/Buttons/ViewButtons.php b/src/Panel/Ui/Buttons/ViewButtons.php index 47ef16be6b..b1c7a78189 100644 --- a/src/Panel/Ui/Buttons/ViewButtons.php +++ b/src/Panel/Ui/Buttons/ViewButtons.php @@ -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) => diff --git a/tests/Cms/Blueprints/BlueprintTest.php b/tests/Cms/Blueprints/BlueprintTest.php index 58910418cb..79e3d192ec 100644 --- a/tests/Cms/Blueprints/BlueprintTest.php +++ b/tests/Cms/Blueprints/BlueprintTest.php @@ -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 */ diff --git a/tests/Panel/Ui/Buttons/ViewButtonsTest.php b/tests/Panel/Ui/Buttons/ViewButtonsTest.php index bebc77e024..ac7fdd710d 100644 --- a/tests/Panel/Ui/Buttons/ViewButtonsTest.php +++ b/tests/Panel/Ui/Buttons/ViewButtonsTest.php @@ -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 */