fix: add fixMenuIcons to postflight for submenu icon params
Joomla only renders img column icons for level-1 menu items. Level 2+ need menu_icon in the params JSON. This runs on every install/update. Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -64,6 +64,9 @@ class Pkg_MokowaasInstallerScript
|
||||
// Create Support portal menu item on frontend
|
||||
$this->setupSupportMenuItem();
|
||||
|
||||
// Set menu_icon params on submenu items (Joomla only renders img on level 1)
|
||||
$this->fixMenuIcons();
|
||||
|
||||
// Mark MokoWaaS extensions as protected (prevents disable/uninstall at framework level)
|
||||
$this->protectExtensions();
|
||||
|
||||
@@ -840,6 +843,69 @@ class Pkg_MokowaasInstallerScript
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Joomla only renders the img column icon for level-1 menu items.
|
||||
* Submenu items (level 2) need menu_icon set in the params JSON.
|
||||
*/
|
||||
private function fixMenuIcons(): void
|
||||
{
|
||||
try
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
|
||||
$iconMap = [
|
||||
'class:cogs' => 'icon-cogs',
|
||||
'class:puzzle-piece' => 'icon-puzzle-piece',
|
||||
'class:headphones' => 'icon-headphones',
|
||||
'class:file-code' => 'icon-file-code',
|
||||
'class:lock' => 'icon-lock',
|
||||
'class:shield-alt' => 'icon-shield-alt',
|
||||
'class:database' => 'icon-database',
|
||||
'class:trash' => 'icon-trash',
|
||||
'class:power-off' => 'icon-power-off',
|
||||
'class:refresh' => 'icon-refresh',
|
||||
'class:check-square' => 'icon-check-square',
|
||||
'class:bolt' => 'icon-bolt',
|
||||
];
|
||||
|
||||
$db->setQuery(
|
||||
"SELECT id, img, params FROM #__menu"
|
||||
. " WHERE client_id = 1 AND level >= 2"
|
||||
. " AND link LIKE '%com_mokowaas%'"
|
||||
);
|
||||
|
||||
foreach ($db->loadObjectList() as $item)
|
||||
{
|
||||
$icon = $iconMap[$item->img] ?? '';
|
||||
|
||||
if (!$icon)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$params = json_decode($item->params ?: '{}', true) ?: [];
|
||||
|
||||
if (!empty($params['menu_icon']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$params['menu_icon'] = $icon;
|
||||
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->update($db->quoteName('#__menu'))
|
||||
->set($db->quoteName('params') . ' = ' . $db->quote(json_encode($params)))
|
||||
->where($db->quoteName('id') . ' = ' . (int) $item->id)
|
||||
)->execute();
|
||||
}
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
Log::add('Menu icon fix error: ' . $e->getMessage(), Log::WARNING, 'mokowaas');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a "Support" menu item on the frontend main menu.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user