feat(main): Groups and blocks
This commit is contained in:
@@ -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']);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user