191 lines
7.5 KiB
PHP
191 lines
7.5 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\Common\ToggleColumn;
|
|
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\TextType;
|
|
|
|
final class CustomHtmlGroupGridDefinitionFactory extends AbstractGridDefinitionFactory
|
|
{
|
|
use DeleteActionTrait;
|
|
|
|
const GRID_ID = 'customhtmlgroup';
|
|
|
|
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 Groups', [], '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_group'))
|
|
->setName($this->trans('ID', [], 'Admin.Global'))
|
|
->setOptions(['field' => 'id_ws_customhtml_group'])
|
|
)
|
|
->add(
|
|
(new DataColumn('title'))
|
|
->setName($this->trans('Title', [], 'Modules.Wscustomhtml.Admin'))
|
|
->setOptions(['field' => 'title'])
|
|
)
|
|
->add(
|
|
(new DataColumn('hook_name'))
|
|
->setName($this->trans('Hook', [], 'Modules.Wscustomhtml.Admin'))
|
|
->setOptions(['field' => 'hook_name'])
|
|
)
|
|
->add(
|
|
(new DataColumn('blocks_count'))
|
|
->setName($this->trans('Blocks', [], 'Modules.Wscustomhtml.Admin'))
|
|
->setOptions(['field' => 'blocks_count', 'sortable' => false])
|
|
)
|
|
->add(
|
|
(new ToggleColumn('active'))
|
|
->setName($this->trans('Active', [], 'Admin.Global'))
|
|
->setOptions([
|
|
'field' => 'active',
|
|
'primary_field' => 'id_ws_customhtml_group',
|
|
'route' => 'customhtmlgroup_toggle',
|
|
'route_param_name' => 'idCustomHtmlGroup',
|
|
])
|
|
)
|
|
->add(
|
|
(new PositionColumn('position'))
|
|
->setName($this->trans('Position', [], 'Admin.Global'))
|
|
->setOptions([
|
|
'id_field' => 'id_ws_customhtml_group',
|
|
'position_field' => 'ordering',
|
|
'update_method' => 'POST',
|
|
'update_route' => 'customhtmlgroup_update_position',
|
|
])
|
|
)
|
|
->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_group', TextType::class))
|
|
->setAssociatedColumn('id_ws_customhtml_group')
|
|
->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('hook_name', TextType::class))
|
|
->setAssociatedColumn('hook_name')
|
|
->setTypeOptions([
|
|
'required' => false,
|
|
'attr' => ['placeholder' => $this->trans('Hook', [], 'Modules.Wscustomhtml.Admin')],
|
|
])
|
|
)
|
|
->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' => 'customhtmlgroup_index',
|
|
])
|
|
);
|
|
}
|
|
|
|
private function buildRowActions(): RowActionCollection
|
|
{
|
|
return (new RowActionCollection())
|
|
->add(
|
|
(new LinkRowAction('view_blocks'))
|
|
->setName($this->trans('View blocks', [], 'Modules.Wscustomhtml.Admin'))
|
|
->setIcon('visibility')
|
|
->setOptions([
|
|
'route' => 'customhtmlblock_index',
|
|
'route_param_name' => 'idGroup',
|
|
'route_param_field' => 'id_ws_customhtml_group',
|
|
])
|
|
)
|
|
->add(
|
|
(new LinkRowAction('add_block'))
|
|
->setName($this->trans('Add block', [], 'Modules.Wscustomhtml.Admin'))
|
|
->setIcon('note_add')
|
|
->setOptions([
|
|
'route' => 'customhtmlblock_create',
|
|
'route_param_name' => 'idGroup',
|
|
'route_param_field' => 'id_ws_customhtml_group',
|
|
])
|
|
)
|
|
->add(
|
|
(new LinkRowAction('edit'))
|
|
->setName($this->trans('Edit', [], 'Admin.Actions'))
|
|
->setIcon('edit')
|
|
->setOptions([
|
|
'route' => 'customhtmlgroup_edit',
|
|
'route_param_name' => 'idCustomHtmlGroup',
|
|
'route_param_field' => 'id_ws_customhtml_group',
|
|
'use_inline_display' => true,
|
|
'clickable_row' => true,
|
|
])
|
|
)
|
|
->add(
|
|
$this->buildDeleteAction('customhtmlgroup_delete', 'idCustomHtmlGroup', 'id_ws_customhtml_group')
|
|
);
|
|
}
|
|
}
|