Skip to content

Commit

Permalink
MenuItem: translatable title, string (url) destination, root requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Jan 25, 2023
1 parent a16c862 commit 507f688
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/UI/Control/Menu/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,51 @@

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
{
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;
}

}

0 comments on commit 507f688

Please sign in to comment.