feat(main): Groups and blocks

This commit is contained in:
2026-08-10 16:13:15 +02:00
parent 6aff506cd6
commit 635c13a0ed
39 changed files with 1188 additions and 237 deletions
+26 -4
View File
@@ -2,7 +2,8 @@
namespace Websmid\CustomHtml\Module;
use Websmid\CustomHtml\Model\CustomHtml;
use Websmid\CustomHtml\Model\CustomHtmlBlock;
use Websmid\CustomHtml\Model\CustomHtmlGroup;
use Context;
trait DisplayHooks
@@ -32,15 +33,36 @@ trait DisplayHooks
public function getWidgetVariables($hookName = null, array $configuration = [])
{
$blockList = CustomHtml::getActiveByHookName((string) $hookName);
$groupList = $this->loadActiveGroupsWithBlocks((string) $hookName);
if (empty($blockList)) {
if (empty($groupList)) {
return [];
}
return [
'hookName' => $hookName,
'blockList' => $blockList,
'groupList' => $groupList,
];
}
private function loadActiveGroupsWithBlocks(string $hookName): array
{
$groups = CustomHtmlGroup::getActiveByHookName($hookName);
if (empty($groups)) {
return [];
}
$blocksByGroup = CustomHtmlBlock::getActiveByGroupIds(array_column($groups, 'id_ws_customhtml_group'));
$groups = array_map(static function (array $group) use ($blocksByGroup) {
$group['blocks'] = $blocksByGroup[(int) $group['id_ws_customhtml_group']] ?? [];
return $group;
}, $groups);
return array_values(array_filter($groups, static function (array $group) {
return !empty($group['blocks']);
}));
}
}