private function loadData()
{
$modules = BackendModel::getModules();
$filesystem = new Filesystem();
// fetch the hidden widgets for all groups the user is in
$hiddenWidgets = [];
$userGroups = BackendAuthentication::getUser()->getGroups();
$groupCount = count($userGroups);
foreach ($userGroups as $group) {
foreach (BackendGroupsModel::getSetting($group, 'hidden_on_dashboard') as $module => $widgets) {
foreach ($widgets as $widget) {
$hiddenWidgets[] = $module . $widget;
}
}
}
// only widgets hidden for all user groups should really be hidden
$hiddenWidgets = array_count_values($hiddenWidgets);
$hiddenWidgets = array_filter($hiddenWidgets, function ($hiddenCount) use($groupCount) {
return $hiddenCount === $groupCount;
});
// loop all modules
foreach ($modules as $module) {
// build pathName
$pathName = BACKEND_MODULES_PATH . '/' . $module;
// you have sufficient rights?
if (BackendAuthentication::isAllowedModule($module) && $filesystem->exists($pathName . '/Widgets')) {
$finder = new Finder();
$finder->name('*.php');
// loop widgets
foreach ($finder->files()->in($pathName . '/Widgets') as $file) {
/** @ver $file \SplFileInfo */
$widgetName = $file->getBasename('.php');
$className = 'Backend\\Modules\\' . $module . '\\Widgets\\' . $widgetName;
if ($module == 'Core') {
$className = 'Backend\\Core\\Widgets\\' . $widgetName;
}
// if the widget is hidden for all the users groups, don't render it
if (array_key_exists($module . $widgetName, $hiddenWidgets)) {
continue;
}
if (!class_exists($className)) {
throw new BackendException('The widgetfile ' . $className . ' could not be found.');
}
// create instance
/** @var $instance BackendBaseWidget */
$instance = new $className($this->getKernel());
// has rights
if (!$instance->isAllowed()) {
continue;
}
$instance->execute();
// user sequence provided?
$title = \SpoonFilter::ucfirst(BL::lbl(\SpoonFilter::toCamelCase($module))) . ': ' . BL::lbl(\SpoonFilter::toCamelCase($widgetName));
$templatePath = $instance->getTemplatePath();
// reset template path
if ($templatePath == null) {
$templatePath = '/' . $module . '/Layout/Widgets/' . $widgetName . '.html.twig';
}
$templating = $this->get('template');
$content = trim($templating->getContent($templatePath));
if (empty($content)) {
continue;
}
// build item
$item = array('content' => $content, 'module' => $module, 'widget' => $widgetName, 'title' => $title);
// add on new position if no position is set or if the position is already used
$this->widgets[] = $item;
}
}
}
}