* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ declare(strict_types=1); namespace PrestaShop\PrestaShop\Core\Grid\Definition\Factory; use PrestaShop\PrestaShop\Core\Grid\Action\Bulk\BulkActionCollection; use PrestaShop\PrestaShop\Core\Grid\Action\Bulk\BulkActionCollectionInterface; use PrestaShop\PrestaShop\Core\Grid\Action\Bulk\Type\SubmitBulkAction; use PrestaShop\PrestaShop\Core\Grid\Action\GridActionCollection; use PrestaShop\PrestaShop\Core\Grid\Action\GridActionCollectionInterface; 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\ColumnCollectionInterface; use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ActionColumn; use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\BulkActionColumn; use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\DataColumn; use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ToggleColumn; use PrestaShop\PrestaShop\Core\Grid\Filter\Filter; use PrestaShop\PrestaShop\Core\Grid\Filter\FilterCollection; use PrestaShop\PrestaShop\Core\Grid\Filter\FilterCollectionInterface; use PrestaShopBundle\Form\Admin\Type\ConfigurableCountryChoiceType; use PrestaShopBundle\Form\Admin\Type\SearchAndResetType; use PrestaShopBundle\Form\Admin\Type\YesAndNoChoiceType; use PrestaShopBundle\Form\Admin\Type\ZoneChoiceType; use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\HttpFoundation\Request; /** * State grid definition */ final class StateGridDefinitionFactory extends AbstractGridDefinitionFactory { use BulkDeleteActionTrait; use DeleteActionTrait; public const GRID_ID = 'state'; /** * {@inheritdoc} */ protected function getId(): string { return self::GRID_ID; } /** * {@inheritdoc} */ protected function getName(): string { return $this->trans('States', [], 'Admin.Navigation.Menu'); } /** * {@inheritdoc} */ protected function getColumns(): ColumnCollectionInterface { return (new ColumnCollection()) ->add( (new BulkActionColumn('states_bulk')) ->setOptions([ 'bulk_field' => 'id_state', ]) ) ->add( (new DataColumn('id_state')) ->setName($this->trans('ID', [], 'Admin.Global')) ->setOptions([ 'field' => 'id_state', ]) ) ->add( (new DataColumn('name')) ->setName($this->trans('Name', [], 'Admin.Global')) ->setOptions([ 'field' => 'name', ]) ) ->add( (new DataColumn('iso_code')) ->setName($this->trans('ISO code', [], 'Admin.International.Feature')) ->setOptions([ 'field' => 'iso_code', ]) ) ->add( (new DataColumn('zone_name')) ->setName($this->trans('Zone', [], 'Admin.Global')) ->setOptions([ 'field' => 'zone_name', ]) ) ->add( (new DataColumn('country_name')) ->setName($this->trans('Country', [], 'Admin.Global')) ->setOptions([ 'field' => 'country_name', ]) ) ->add( (new ToggleColumn('active')) ->setName($this->trans('Enabled', [], 'Admin.Global')) ->setOptions([ 'field' => 'active', 'primary_field' => 'id_state', 'route' => 'admin_states_toggle_status', 'route_param_name' => 'stateId', 'sortable' => false, ]) ) ->add( (new ActionColumn('actions')) ->setName($this->trans('Actions', [], 'Admin.Global')) ->setOptions([ 'actions' => (new RowActionCollection()) ->add( (new LinkRowAction('edit')) ->setName($this->trans('Edit', [], 'Admin.Actions')) ->setIcon('edit') ->setOptions([ 'route' => 'admin_states_edit', 'route_param_name' => 'stateId', 'route_param_field' => 'id_state', ]) ) ->add( $this->buildDeleteAction( 'admin_states_delete', 'stateId', 'id_state', Request::METHOD_DELETE ) ), ]) ); } /** * {@inheritdoc} */ protected function getFilters(): FilterCollectionInterface { return (new FilterCollection()) ->add( (new Filter('id_state', NumberType::class)) ->setTypeOptions([ 'attr' => [ 'placeholder' => $this->trans('Search ID', [], 'Admin.Actions'), ], 'required' => false, ]) ->setAssociatedColumn('id_state') ) ->add( (new Filter('name', TextType::class)) ->setTypeOptions([ 'attr' => [ 'placeholder' => $this->trans('Search name', [], 'Admin.Actions'), ], 'required' => false, ]) ->setAssociatedColumn('name') ) ->add( (new Filter('iso_code', TextType::class)) ->setTypeOptions([ 'attr' => [ 'placeholder' => $this->trans('Search ISO code', [], 'Admin.Actions'), ], 'required' => false, ]) ->setAssociatedColumn('iso_code') ) ->add( (new Filter('id_zone', ZoneChoiceType::class)) ->setTypeOptions([ 'required' => false, ]) ->setAssociatedColumn('zone_name') ) ->add( (new Filter('id_country', ConfigurableCountryChoiceType::class)) ->setTypeOptions([ 'required' => false, 'contains_states' => true, 'choice_translation_domain' => false, ]) ->setAssociatedColumn('country_name') ) ->add( (new Filter('active', YesAndNoChoiceType::class)) ->setAssociatedColumn('active') ) ->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' => 'admin_states_index', ]) ); } /** * {@inheritdoc} */ protected function getGridActions(): GridActionCollectionInterface { return (new GridActionCollection()) ->add( (new SimpleGridAction('common_refresh_list')) ->setName($this->trans('Refresh list', [], 'Admin.Advparameters.Feature')) ->setIcon('refresh') ) ->add( (new SimpleGridAction('common_show_query')) ->setName($this->trans('Show SQL query', [], 'Admin.Actions')) ->setIcon('code') ) ->add( (new SimpleGridAction('common_export_sql_manager')) ->setName($this->trans('Export to SQL Manager', [], 'Admin.Actions')) ->setIcon('storage') ); } /** * {@inheritdoc} */ protected function getBulkActions(): BulkActionCollectionInterface { return (new BulkActionCollection()) ->add( (new SubmitBulkAction('enable_selection')) ->setName($this->trans('Enable selection', [], 'Admin.Actions')) ->setOptions([ 'submit_route' => 'admin_states_bulk_enable_status', ]) ) ->add( (new SubmitBulkAction('disable_selection')) ->setName($this->trans('Disable selection', [], 'Admin.Actions')) ->setOptions([ 'submit_route' => 'admin_states_bulk_disable_status', ]) ) ->add( $this->buildBulkDeleteAction('admin_states_delete_bulk') ); } }