Simplify AddonHelper::getAvailableAddons(), move style logic into Module class

This commit is contained in:
Art4 2025-02-04 13:48:04 +00:00
parent af1894504d
commit a80bf0ddf1
4 changed files with 30 additions and 8 deletions

View file

@ -124,8 +124,7 @@ HELP;
return false; return false;
} }
foreach ($this->addonHelper->getAvailableAddons() as $addon) { foreach ($this->addonHelper->getAvailableAddons() as $addonId) {
$addonId = $addon[0];
$enabled = $this->addonHelper->isAddonEnabled($addonId); $enabled = $this->addonHelper->isAddonEnabled($addonId);
if ($subCmd === 'all') { if ($subCmd === 'all') {

View file

@ -22,11 +22,12 @@ interface AddonHelper
public function getAddonPath(): string; public function getAddonPath(): string;
/** /**
* Returns the list of available addons with their current status and info. * Returns the list of available addons.
*
* This list is made from scanning the addon/ folder. * This list is made from scanning the addon/ folder.
* Unsupported addons are excluded unless they already are enabled or system.show_unsupported_addon is set. * Unsupported addons are excluded unless they already are enabled or system.show_unsupported_addon is set.
* *
* @return array<array<string|string|array>> * @return string[]
*/ */
public function getAvailableAddons(): array; public function getAvailableAddons(): array;

View file

@ -36,15 +36,21 @@ final class AddonProxy implements AddonHelper
} }
/** /**
* Returns the list of available addons with their current status and info. * Returns the list of available addons.
*
* This list is made from scanning the addon/ folder. * This list is made from scanning the addon/ folder.
* Unsupported addons are excluded unless they already are enabled or system.show_unsupported_addon is set. * Unsupported addons are excluded unless they already are enabled or system.show_unsupported_addon is set.
* *
* @return array<array<string|string|array>> * @return string[]
*/ */
public function getAvailableAddons(): array public function getAvailableAddons(): array
{ {
return Addon::getAvailableList(); return array_map(
function(array $item) {
return $item[0];
},
Addon::getAvailableList()
);
} }
/** /**

View file

@ -54,7 +54,23 @@ class Index extends BaseAdmin
DI::baseUrl()->redirect('admin/addons'); DI::baseUrl()->redirect('admin/addons');
} }
$addons = $addonHelper->getAvailableAddons(); $addons = [];
foreach ($addonHelper->getAvailableAddons() as $addonId) {
$addonInfo = $addonHelper->getAddonInfo($addonId);
$info = [
'name' => $addonInfo->getName(),
'description' => $addonInfo->getDescription(),
'version' => $addonInfo->getVersion(),
];
$addons[] = [
$addonId,
($addonHelper->isAddonEnabled($addonId) ? 'on' : 'off'),
$info,
];
}
$t = Renderer::getMarkupTemplate('admin/addons/index.tpl'); $t = Renderer::getMarkupTemplate('admin/addons/index.tpl');
return Renderer::replaceMacros($t, [ return Renderer::replaceMacros($t, [