diff --git a/plugins/system/stats/src/Field/DataField.php b/plugins/system/stats/src/Field/DataField.php index c55db76f28721..4097ca3cee894 100644 --- a/plugins/system/stats/src/Field/DataField.php +++ b/plugins/system/stats/src/Field/DataField.php @@ -13,6 +13,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; +use Joomla\Registry\Registry; /** * Unique ID Field class for the Stats Plugin. @@ -52,8 +53,35 @@ protected function getLayoutData() $result = Factory::getApplication()->triggerEvent('onGetStatsData', array('stats.field.data')); - $data['statsData'] = $result ? reset($result) : array(); + // If the plugin is disabled, we need to compile the stats manually + if (!$result) + { + $stats = Factory::getApplication()->bootPlugin('stats', 'system'); + $stats->params = new Registry(\json_decode($this->getParams())); + $result = [$stats->onGetStatsData('')]; + } + + $data['statsData'] = reset($result); return $data; } + + /** + * If the plugin is disabled, we need to compile the stats manually, for that we need the params from the db. + * + * @return string The JSON of the params of this plugin. + */ + private function getParams() + { + $db = Factory::getContainer()->get('DatabaseDriver'); + + $query = $db->getQuery(true) + ->select('params') + ->from('#__extensions') + ->where($db->quoteName('name') . ' = ' . $db->quote('plg_system_stats')); + + $db->setQuery($query); + + return $db->loadResult(); + } }