diff --git a/source/packages/plg_system_mokosuiteclient/Extension/MokoSuiteClient.php b/source/packages/plg_system_mokosuiteclient/Extension/MokoSuiteClient.php index c2dfc64d..7a998157 100644 --- a/source/packages/plg_system_mokosuiteclient/Extension/MokoSuiteClient.php +++ b/source/packages/plg_system_mokosuiteclient/Extension/MokoSuiteClient.php @@ -2904,4 +2904,68 @@ class MokoSuiteClient extends CMSPlugin implements BootableExtensionInterface Log::add('Cache auto-clear failed: ' . $e->getMessage(), Log::WARNING, 'mokosuiteclient'); } } + + // ------------------------------------------------------------------ + // Advanced Module Manager — Conditions-based filtering (#160) + // ------------------------------------------------------------------ + + /** + * Filter the site module list based on ConditionsHelper rules. + * + * Modules that have no condition mappings pass through unchanged. + * Modules with condition sets are evaluated; only those whose + * conditions are satisfied for the current request are kept. + * + * @param array|null &$modules The list of module objects Joomla will render. + * + * @return void + * + * @since 02.47.52 + */ + public function onPrepareModuleList(?array &$modules): void + { + if ($modules === null || !$this->getApplication()->isClient('site')) + { + return; + } + + // Only filter if the conditions map table exists + try + { + $db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class); + $tables = $db->getTableList(); + $prefix = $db->getPrefix(); + + if (!\in_array($prefix . 'mokosuiteclient_conditions_map', $tables, true)) + { + return; + } + } + catch (\Throwable $e) + { + return; + } + + $filtered = []; + + foreach ($modules as $module) + { + $moduleId = (int) ($module->id ?? 0); + + if ($moduleId <= 0) + { + $filtered[] = $module; + continue; + } + + // ConditionsHelper::shouldDisplay returns true when no conditions + // are mapped (module shows everywhere) or when conditions pass. + if (\Moko\Component\MokoSuiteClient\Administrator\Helper\ConditionsHelper::shouldDisplay('com_modules', $moduleId)) + { + $filtered[] = $module; + } + } + + $modules = $filtered; + } }