From 507f6886b5dc61dac1fbd7349b564ec93b504e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Barto=C5=A1?= Date: Thu, 26 Jan 2023 00:35:39 +0100 Subject: [PATCH] MenuItem: translatable title, string (url) destination, root requirement --- src/UI/Control/Menu/MenuItem.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/UI/Control/Menu/MenuItem.php b/src/UI/Control/Menu/MenuItem.php index 3a87baf..13be033 100644 --- a/src/UI/Control/Menu/MenuItem.php +++ b/src/UI/Control/Menu/MenuItem.php @@ -4,33 +4,36 @@ use Closure; use OriCMF\UI\ActionLink; +use Orisai\TranslationContracts\Translatable; -/** - * @todo - external url - */ final class MenuItem { /** - * @param Closure(): ActionLink $destination + * @param Closure(): ActionLink|string $destination */ public function __construct( - private readonly string $title, - private readonly Closure $destination, + private readonly Translatable|string $title, + private readonly Closure|string $destination, private readonly string|null $icon = null, - private readonly string|null $privilege = null, + private readonly string|null $requiredPrivilege = null, + private readonly bool $requiresRoot = false, ) { } - public function getTitle(): string + public function getTitle(): Translatable|string { return $this->title; } - public function getDestination(): ActionLink + public function getDestination(): ActionLink|string { - return ($this->destination)(); + if ($this->destination instanceof Closure) { + return ($this->destination)(); + } + + return $this->destination; } public function getIcon(): string|null @@ -38,9 +41,14 @@ public function getIcon(): string|null return $this->icon; } - public function getPrivilege(): string|null + public function getRequiredPrivilege(): string|null + { + return $this->requiredPrivilege; + } + + public function isRootRequired(): bool { - return $this->privilege; + return $this->requiresRoot; } }