Files
InvoiceShelf/app/Platform/Operations/Http/Concerns/GeneratesMenu.php
T
Darko Gjorgjijoski 7db2a8d094 feat(operations): fresh platform-operations implementation
Full rewrite of the installer (incl. the finish step), self-update pipeline,
settings store, cron webhook, dashboard/bootstrap surface, environment
manager, wizard login, config endpoint and shared helpers. Byte-compatible
public interfaces and observable behavior, including documented legacy
quirks; verified by the pilot behavioral suite and the full test suite.
2026-08-20 18:30:12 +02:00

53 lines
1.3 KiB
PHP

<?php
namespace App\Platform\Operations\Http\Concerns;
/**
* Flattens a registered navigation tree into the plain arrays the SPA renders.
*/
trait GeneratesMenu
{
/**
* Read one registered menu and drop every entry this user may not see.
*
* Visibility itself is decided by the user model; this only asks.
*/
public function generateMenu($key, $user)
{
$navigation = \Menu::get($key);
if (! $navigation) {
return [];
}
$visible = [];
foreach ($navigation->items->toArray() as $entry) {
if ($user->checkAccess($entry)) {
$visible[] = $this->describeMenuEntry($entry);
}
}
return $visible;
}
/**
* One navigation entry in wire shape. Grouping label and ordering weight
* are optional in the menu definition, so they fall back here.
*/
private function describeMenuEntry(object $entry): array
{
$meta = $entry->data;
return [
'title' => $entry->title,
'link' => $entry->link->path['url'],
'icon' => $meta['icon'],
'name' => $meta['name'],
'group' => $meta['group'],
'group_label' => $meta['group_label'] ?? '',
'priority' => $meta['priority'] ?? 100,
];
}
}