From c46dd3198d72849934dd9b309835fc79c0ff46d0 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Tue, 19 Nov 2024 12:15:53 +0100 Subject: [PATCH] [Admin] Replace custom invoice_channel filter with entity filter from GridBundle --- UPGRADE.md | 15 ++++++ src/Form/Type/ChannelFilterType.php | 48 ------------------- src/Grid/Filter/ChannelFilter.php | 32 ------------- src/Resources/config/config.yml | 7 ++- src/Resources/config/services/ui.xml | 9 ---- .../views/Grid/Filter/channel.html.twig | 3 -- tests/Behat/Page/Admin/Invoice/IndexPage.php | 2 +- 7 files changed, 19 insertions(+), 97 deletions(-) delete mode 100644 src/Form/Type/ChannelFilterType.php delete mode 100644 src/Grid/Filter/ChannelFilter.php delete mode 100644 src/Resources/views/Grid/Filter/channel.html.twig diff --git a/UPGRADE.md b/UPGRADE.md index 8b9a0b8a..ed9530b8 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -27,10 +27,17 @@ - `@SyliusInvoicingPlugin/Invoice/Grid/Field/orderNumber.html.twig` - `@SyliusInvoicingPlugin/Invoice/Grid/Field/channel.html.twig` +1. The custom `invoice_channel` filter, its `Sylius\InvoicingPlugin\Grid\Filter\ChannelFilter` class + and `Sylius\InvoicingPlugin\Form\Type\ChannelFilterType` form type have been removed and replaced by + the `entity` filter from GridBundle. + 1. The invoice grid configuration has been updated accordingly to the above changes: ```diff sylius_grid: + - templates: + - filter: + - invoice_channel: '@SyliusInvoicingPlugin/Grid/Filter/channel.html.twig' grids: sylius_invoicing_plugin_invoice: # ... @@ -52,5 +59,13 @@ options: - template: "@SyliusInvoicingPlugin/Invoice/Grid/Field/channel.html.twig" + template: "@SyliusAdmin/Order/Grid/Field/channel.html.twig" + filters: + # ... + channel: + - type: invoice_channel + + type: entity + label: sylius.ui.channel + + form_options: + + class: "%sylius.model.channel.class%" # ... ``` diff --git a/src/Form/Type/ChannelFilterType.php b/src/Form/Type/ChannelFilterType.php deleted file mode 100644 index 314f1469..00000000 --- a/src/Form/Type/ChannelFilterType.php +++ /dev/null @@ -1,48 +0,0 @@ -add('channel', ChoiceType::class, [ - 'choices' => $this->getChannelsList(), - 'label' => false, - 'placeholder' => 'sylius.ui.all', - ]); - } - - private function getChannelsList(): array - { - $channels = []; - - /** @var ChannelInterface $channel */ - foreach ($this->channelRepository->findBy(['enabled' => true]) as $channel) { - $channels[$channel->getName()] = $channel->getCode(); - } - - return $channels; - } -} diff --git a/src/Grid/Filter/ChannelFilter.php b/src/Grid/Filter/ChannelFilter.php deleted file mode 100644 index 15bc9d69..00000000 --- a/src/Grid/Filter/ChannelFilter.php +++ /dev/null @@ -1,32 +0,0 @@ -restrict($dataSource->getExpressionBuilder()->equals('o.channel.code', $data['channel'])); - } -} diff --git a/src/Resources/config/config.yml b/src/Resources/config/config.yml index 35127f73..be3bae31 100644 --- a/src/Resources/config/config.yml +++ b/src/Resources/config/config.yml @@ -27,9 +27,6 @@ winzou_state_machine: args: ['object'] sylius_grid: - templates: - filter: - invoice_channel: '@SyliusInvoicingPlugin/Grid/Filter/channel.html.twig' grids: sylius_invoicing_plugin_invoice: driver: @@ -81,8 +78,10 @@ sylius_grid: type: date label: sylius_invoicing.ui.issued_at channel: - type: invoice_channel + type: entity label: sylius.ui.channel + form_options: + class: "%sylius.model.channel.class%" actions: item: show: diff --git a/src/Resources/config/services/ui.xml b/src/Resources/config/services/ui.xml index c20ea711..0e359e58 100644 --- a/src/Resources/config/services/ui.xml +++ b/src/Resources/config/services/ui.xml @@ -7,14 +7,5 @@ - - - - - - - - - diff --git a/src/Resources/views/Grid/Filter/channel.html.twig b/src/Resources/views/Grid/Filter/channel.html.twig deleted file mode 100644 index 81480fcd..00000000 --- a/src/Resources/views/Grid/Filter/channel.html.twig +++ /dev/null @@ -1,3 +0,0 @@ -{% form_theme form '@SyliusUi/Form/theme.html.twig' %} - -{{ form_row(form) }} diff --git a/tests/Behat/Page/Admin/Invoice/IndexPage.php b/tests/Behat/Page/Admin/Invoice/IndexPage.php index 84a99325..abd56c60 100644 --- a/tests/Behat/Page/Admin/Invoice/IndexPage.php +++ b/tests/Behat/Page/Admin/Invoice/IndexPage.php @@ -22,6 +22,6 @@ public function hasInvoiceWithChannel(int $index, string $channel): bool public function filterByChannel(string $channelName): void { - $this->getDocument()->find('css', '#criteria_channel_channel')->selectOption($channelName); + $this->getDocument()->find('css', '#criteria_channel')->selectOption($channelName); } }