Skip to content

Commit

Permalink
MenuItem: Fix compatbility with submenu from plugin menuItem.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Sep 26, 2022
1 parent 4ab900a commit 8b36655
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
33 changes: 33 additions & 0 deletions src/Menu/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,37 @@ public function __construct(
public array $child = [],
) {
}


/**
* @param array{
* service: string,
* type: class-string<Plugin>,
* name: string,
* realName: string,
* baseEntity: string|null,
* label: string,
* basePath: string,
* priority: int,
* icon: string|null,
* roles: array<int, string>,
* privileges: array<int, string>,
* menuItem: array<string, string|null>|null
* } $plugin
*/
public static function fromPluginDefinition(array $plugin): self
{
return new self(
key: $plugin['service'],
title: $plugin['label'],
pluginName: $plugin['name'],
priority: $plugin['priority'],
link: sprintf(
'%s/%s',
Configuration::get()->getBaseUri(), Helpers::formatPresenterNameToUri($plugin['name']),
),
icon: $plugin['icon'] ?? null,
child: [],
);
}
}
20 changes: 4 additions & 16 deletions src/Menu/MenuManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,10 @@ public function getItems(): array
if (isset($this->ignorePlugins[$plugin['type']]) === true) {
continue;
}
$menuItem = $plugin['menuItem'] ?? null;
if ($menuItem !== null) {
$return[] = $menuItem;
continue;
}
$route = Helpers::formatPresenterNameToUri($plugin['name']);
if ($this->authorizator->get()->isAllowedPlugin($route)) {
$return[] = new MenuItem(
key: $plugin['service'],
title: $plugin['label'],
pluginName: $plugin['name'],
priority: $plugin['priority'],
link: Configuration::get()->getBaseUri() . '/' . $route,
icon: $plugin['icon'] ?? null,
child: [],
);
if (isset($plugin['menuItem'])) {
$return[] = MenuItem::fromPluginDefinition($plugin['menuItem']);
} elseif ($this->authorizator->get()->isAllowedPlugin(Helpers::formatPresenterNameToUri($plugin['name']))) {
$return[] = MenuItem::fromPluginDefinition($plugin);
}
}

Expand Down

0 comments on commit 8b36655

Please sign in to comment.