48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Websmid\CustomHtml\Module;
|
|
|
|
use Websmid\CustomHtml\Config\Config;
|
|
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
|
|
use PrestaShop\PrestaShop\Core\Grid\Data\GridData;
|
|
use PrestaShop\PrestaShop\Core\Grid\Record\RecordCollection;
|
|
use Tools;
|
|
|
|
trait AdminHooks
|
|
{
|
|
public function isUsingNewTranslationSystem(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function getContent()
|
|
{
|
|
Tools::redirectAdmin($this->get('router')->generate('customhtmlgroup_index'));
|
|
}
|
|
|
|
public function hookActionAdminControllerSetMedia(): void
|
|
{
|
|
$request = SymfonyContainer::getInstance()->get('request_stack')->getCurrentRequest();
|
|
$routeName = $request ? (string) $request->attributes->get('_route') : '';
|
|
|
|
if (0 !== strpos($routeName, 'customhtml')) {
|
|
return;
|
|
}
|
|
|
|
$this->context->controller->addCSS($this->getPathUri() . 'views/css/admin/grid.css');
|
|
}
|
|
|
|
public function hookActionCustomhtmlblockGridDataModifier(array $params): void
|
|
{
|
|
$gridData = $params['data'];
|
|
|
|
$records = array_map(static function (array $row) {
|
|
$row['type'] = Config::BLOCK_TYPES[$row['type']] ?? $row['type'];
|
|
|
|
return $row;
|
|
}, $gridData->getRecords()->all());
|
|
|
|
$params['data'] = new GridData(new RecordCollection($records), $gridData->getRecordsTotal(), $gridData->getQuery());
|
|
}
|
|
}
|