feat(main): Groups and blocks
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Websmid\CustomHtml\Module;
|
||||
|
||||
use Websmid\CustomHtml\Config\Config;
|
||||
use Tools;
|
||||
|
||||
trait AdminHooks
|
||||
@@ -13,6 +14,17 @@ trait AdminHooks
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
Tools::redirectAdmin($this->get('router')->generate('customhtml_index'));
|
||||
Tools::redirectAdmin($this->get('router')->generate('customhtmlgroup_index'));
|
||||
}
|
||||
|
||||
public function hookActionAdminControllerSetMedia(): void
|
||||
{
|
||||
$controllerName = $this->context->controller->controller_name ?? '';
|
||||
|
||||
if (!in_array($controllerName, Config::ADMIN_CONTROLLERS, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->context->controller->addCSS($this->getPathUri() . 'views/css/admin/grid.css');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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']);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
+15
-2
@@ -38,17 +38,30 @@ trait Install
|
||||
{
|
||||
$sqlToExec = [];
|
||||
|
||||
$sqlToExec[] = '
|
||||
CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml_group (
|
||||
`id_ws_customhtml_group` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
`hook_name` VARCHAR(64) NOT NULL,
|
||||
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
|
||||
`active` TINYINT(1) NOT NULL DEFAULT 1,
|
||||
`ordering` INT(11) NOT NULL DEFAULT 0,
|
||||
`date_add` DATETIME NOT NULL,
|
||||
`date_upd` DATETIME NOT NULL
|
||||
);
|
||||
';
|
||||
|
||||
$sqlToExec[] = '
|
||||
CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml (
|
||||
`id_ws_customhtml` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
`hook_name` VARCHAR(64) NOT NULL,
|
||||
`id_ws_customhtml_group` INT(11) NOT NULL,
|
||||
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
|
||||
`content` LONGTEXT,
|
||||
`active` TINYINT(1) NOT NULL DEFAULT 1,
|
||||
`show_title` TINYINT(1) NOT NULL DEFAULT 0,
|
||||
`ordering` INT(11) NOT NULL DEFAULT 0,
|
||||
`date_add` DATETIME NOT NULL,
|
||||
`date_upd` DATETIME NOT NULL
|
||||
`date_upd` DATETIME NOT NULL,
|
||||
KEY `id_ws_customhtml_group` (`id_ws_customhtml_group`)
|
||||
);
|
||||
';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user