187 lines
7.2 KiB
PHP
187 lines
7.2 KiB
PHP
<?php
|
|
|
|
namespace Websmid\CustomHtml\Grid\Definition\Factory;
|
|
|
|
use PrestaShop\PrestaShop\Core\Grid\Action\GridActionCollection;
|
|
use PrestaShop\PrestaShop\Core\Grid\Action\Row\RowActionCollection;
|
|
use PrestaShop\PrestaShop\Core\Grid\Action\Row\Type\LinkRowAction;
|
|
use PrestaShop\PrestaShop\Core\Grid\Action\Type\SimpleGridAction;
|
|
use PrestaShop\PrestaShop\Core\Grid\Column\ColumnCollection;
|
|
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ActionColumn;
|
|
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\PositionColumn;
|
|
use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
|
|
use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory;
|
|
use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\DeleteActionTrait;
|
|
use PrestaShop\PrestaShop\Core\Grid\Filter\Filter;
|
|
use PrestaShop\PrestaShop\Core\Grid\Filter\FilterCollection;
|
|
use PrestaShop\PrestaShop\Core\Hook\HookDispatcherInterface;
|
|
use PrestaShopBundle\Form\Admin\Type\SearchAndResetType;
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|
use Websmid\CustomHtml\Config\Config;
|
|
|
|
final class CustomHtmlBlockGridDefinitionFactory extends AbstractGridDefinitionFactory
|
|
{
|
|
use DeleteActionTrait;
|
|
|
|
const GRID_ID = 'customhtmlblock';
|
|
|
|
public function __construct(HookDispatcherInterface $dispatcher)
|
|
{
|
|
parent::__construct($dispatcher);
|
|
}
|
|
|
|
protected function getId(): string
|
|
{
|
|
return self::GRID_ID;
|
|
}
|
|
|
|
protected function getName(): string
|
|
{
|
|
return $this->trans('Custom HTML Blocks', [], 'Modules.Wscustomhtml.Admin');
|
|
}
|
|
|
|
protected function getGridActions()
|
|
{
|
|
return (new GridActionCollection())
|
|
->add(
|
|
(new SimpleGridAction('common_refresh_list'))
|
|
->setName($this->trans('Refresh list', [], 'Admin.Catalog.Feature'))
|
|
->setIcon('refresh')
|
|
)
|
|
->add(
|
|
(new SimpleGridAction('common_show_query'))
|
|
->setName($this->trans('Show SQL query', [], 'Admin.Catalog.Feature'))
|
|
->setIcon('code')
|
|
);
|
|
}
|
|
|
|
protected function getColumns()
|
|
{
|
|
return (new ColumnCollection())
|
|
->add(
|
|
(new DataColumn('id_ws_customhtml'))
|
|
->setName($this->trans('ID', [], 'Admin.Global'))
|
|
->setOptions(['field' => 'id_ws_customhtml'])
|
|
)
|
|
->add(
|
|
(new DataColumn('title'))
|
|
->setName($this->trans('Title', [], 'Modules.Wscustomhtml.Admin'))
|
|
->setOptions(['field' => 'title'])
|
|
)
|
|
->add(
|
|
(new DataColumn('group_title'))
|
|
->setName($this->trans('Group', [], 'Modules.Wscustomhtml.Admin'))
|
|
->setOptions(['field' => 'group_title'])
|
|
)
|
|
->add(
|
|
(new DataColumn('type'))
|
|
->setName($this->trans('Type', [], 'Modules.Wscustomhtml.Admin'))
|
|
->setOptions(['field' => 'type'])
|
|
)
|
|
->add(
|
|
(new DataColumn('active'))
|
|
->setName($this->trans('Active', [], 'Admin.Global'))
|
|
->setOptions(['field' => 'active'])
|
|
)
|
|
->add(
|
|
(new PositionColumn('position'))
|
|
->setName($this->trans('Position', [], 'Modules.Wscustomhtml.Admin'))
|
|
->setOptions([
|
|
'id_field' => 'id_ws_customhtml',
|
|
'position_field' => 'ordering',
|
|
'update_method' => 'POST',
|
|
'update_route' => 'customhtmlblock_update_position',
|
|
'record_route_params' => [
|
|
'id_ws_customhtml_group' => 'idGroup',
|
|
],
|
|
'required_filter' => 'id_ws_customhtml_group',
|
|
])
|
|
)
|
|
->add(
|
|
(new DataColumn('date_add'))
|
|
->setName($this->trans('Date added', [], 'Admin.Global'))
|
|
->setOptions(['field' => 'date_add'])
|
|
)
|
|
->add(
|
|
(new ActionColumn('actions'))
|
|
->setName($this->trans('Actions', [], 'Admin.Global'))
|
|
->setOptions(['actions' => $this->buildRowActions()])
|
|
);
|
|
}
|
|
|
|
protected function getFilters()
|
|
{
|
|
return (new FilterCollection())
|
|
->add(
|
|
(new Filter('id_ws_customhtml', TextType::class))
|
|
->setAssociatedColumn('id_ws_customhtml')
|
|
->setTypeOptions([
|
|
'required' => false,
|
|
'attr' => ['placeholder' => $this->trans('ID', [], 'Admin.Global')],
|
|
])
|
|
)
|
|
->add(
|
|
(new Filter('title', TextType::class))
|
|
->setAssociatedColumn('title')
|
|
->setTypeOptions([
|
|
'required' => false,
|
|
'attr' => ['placeholder' => $this->trans('Title', [], 'Modules.Wscustomhtml.Admin')],
|
|
])
|
|
)
|
|
->add(
|
|
(new Filter('group_title', TextType::class))
|
|
->setAssociatedColumn('group_title')
|
|
->setTypeOptions([
|
|
'required' => false,
|
|
'attr' => ['placeholder' => $this->trans('Group', [], 'Modules.Wscustomhtml.Admin')],
|
|
])
|
|
)
|
|
->add(
|
|
(new Filter('type', ChoiceType::class))
|
|
->setAssociatedColumn('type')
|
|
->setTypeOptions([
|
|
'required' => false,
|
|
'choices' => array_flip(Config::BLOCK_TYPES),
|
|
'placeholder' => $this->trans('All', [], 'Admin.Global'),
|
|
])
|
|
)
|
|
->add(
|
|
(new Filter('actions', SearchAndResetType::class))
|
|
->setAssociatedColumn('actions')
|
|
->setTypeOptions([
|
|
'reset_route' => 'admin_common_reset_search_by_filter_id',
|
|
'reset_route_params' => ['filterId' => self::GRID_ID],
|
|
'redirect_route' => 'customhtmlblock_index',
|
|
])
|
|
);
|
|
}
|
|
|
|
private function buildRowActions(): RowActionCollection
|
|
{
|
|
return (new RowActionCollection())
|
|
->add(
|
|
(new LinkRowAction('edit'))
|
|
->setName($this->trans('Edit', [], 'Admin.Actions'))
|
|
->setIcon('edit')
|
|
->setOptions([
|
|
'route' => 'customhtmlblock_edit',
|
|
'route_param_name' => 'idCustomHtmlBlock',
|
|
'route_param_field' => 'id_ws_customhtml',
|
|
'use_inline_display' => true,
|
|
'clickable_row' => true,
|
|
'extra_route_params' => ['idGroup' => 'id_ws_customhtml_group'],
|
|
])
|
|
)
|
|
->add(
|
|
$this->buildDeleteAction(
|
|
'customhtmlblock_delete',
|
|
'idCustomHtmlBlock',
|
|
'id_ws_customhtml',
|
|
'POST',
|
|
['idGroup' => 'id_ws_customhtml_group']
|
|
)
|
|
);
|
|
}
|
|
}
|