feat(main): Groups and blocks
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
<?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\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 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('active'))
|
||||
->setName($this->trans('Active', [], 'Admin.Global'))
|
||||
->setOptions(['field' => 'active'])
|
||||
)
|
||||
->add(
|
||||
(new DataColumn('ordering'))
|
||||
->setName($this->trans('Position', [], 'Modules.Wscustomhtml.Admin'))
|
||||
->setOptions(['field' => 'ordering'])
|
||||
)
|
||||
->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('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,
|
||||
])
|
||||
)
|
||||
->add(
|
||||
$this->buildDeleteAction('customhtmlblock_delete', 'idCustomHtmlBlock', 'id_ws_customhtml')
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user