diff --git a/src/script.php b/src/script.php index 5d55bf36..56ea66de 100644 --- a/src/script.php +++ b/src/script.php @@ -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. */