Skip to content

Commit 9cfe317

Browse files
authored
Merge pull request #304 from bitExpert-forks/feature/sylius_v2
Sylius 2.x compatibility
2 parents 1a53829 + f1d7095 commit 9cfe317

File tree

80 files changed

+290
-554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+290
-554
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,12 @@ jobs:
2121
strategy:
2222
fail-fast: false
2323
matrix:
24-
php: [8.1]
25-
symfony: [^5.4, ^6.0]
26-
sylius: [~1.11.0, ~1.12.0, ~1.13.0, ~1.14.0]
27-
node: [18.x]
24+
php: [8.2]
25+
symfony: [^6.4, ^7.1]
26+
sylius: [~2.0]
27+
node: [20.x]
2828
mysql: [5.7]
2929

30-
exclude:
31-
-
32-
sylius: ~1.11.0
33-
symfony: ^6.0
34-
3530
env:
3631
APP_ENV: test
3732
DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?serverVersion=${{ matrix.mysql }}"
@@ -89,7 +84,7 @@ jobs:
8984

9085
-
9186
name: Cache Composer
92-
uses: actions/cache@v2
87+
uses: actions/cache@v4
9388
with:
9489
path: ${{ steps.composer-cache.outputs.dir }}
9590
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json **/composer.lock') }}
@@ -120,7 +115,7 @@ jobs:
120115

121116
-
122117
name: Cache Yarn
123-
uses: actions/cache@v2
118+
uses: actions/cache@v4
124119
with:
125120
path: ${{ steps.yarn-cache.outputs.dir }}
126121
key: ${{ runner.os }}-node-${{ matrix.node }}-yarn-${{ hashFiles('**/package.json **/yarn.lock') }}

composer.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"description": "import / export plugin for Sylius.",
55
"license": "MIT",
66
"require": {
7-
"php": "^8.1",
8-
"sylius/sylius": "~1.11.0 || ~1.12.0 || ~1.13.0 || ~1.14.0",
7+
"php": "^8.2",
8+
"sylius/sylius": "~2.0",
99
"portphp/portphp": "^1.2",
1010
"queue-interop/queue-interop": "^0.6.2 || ^0.7 || ^0.8",
11-
"symfony/stopwatch": "^5.2 || ^6.0"
11+
"symfony/stopwatch": "^6.4 || ^7.1"
1212
},
1313
"suggest": {
1414
"portphp/spreadsheet": "To support importing Excel and LibreOffice Calc files, use version ^1.1",
@@ -37,13 +37,13 @@
3737
"phpstan/phpstan-webmozart-assert": "0.12.12",
3838
"phpunit/phpunit": "^9.5",
3939
"sylius-labs/coding-standard": "^3.2 || ^4.0",
40-
"symfony/browser-kit": "^5.4 || ^6.0",
41-
"symfony/debug-bundle": "^5.4 || ^6.0",
42-
"symfony/dotenv": "^5.4 || ^6.0",
43-
"symfony/intl": "^5.4 || ^6.0",
44-
"symfony/mailer": "^5.4 || ^6.0",
45-
"symfony/webpack-encore-bundle": "^1.15",
46-
"symfony/web-profiler-bundle": "^5.4 || ^6.0",
40+
"symfony/browser-kit": "^6.4 || ^7.1",
41+
"symfony/debug-bundle": "^6.4 || ^7.1",
42+
"symfony/dotenv": "^6.4 || ^7.1",
43+
"symfony/intl": "^6.4 || ^7.1",
44+
"symfony/mailer": "^6.4 || ^7.1",
45+
"symfony/webpack-encore-bundle": "^1.15 || ^2.2",
46+
"symfony/web-profiler-bundle": "^6.4 || ^7.1",
4747
"portphp/csv": "^1.1.0",
4848
"portphp/spreadsheet": "^1.0.0-alpha",
4949
"predis/predis": "^1.1"
@@ -71,6 +71,7 @@
7171
"config": {
7272
"allow-plugins": {
7373
"dealerdirect/phpcodesniffer-composer-installer": true,
74+
"php-http/discovery": true,
7475
"phpstan/extension-installer": true,
7576
"symfony/flex": true,
7677
"symfony/thanks": false

src/Command/ExportDataCommand.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
use Symfony\Component\Console\Input\InputOption;
1515
use Symfony\Component\Console\Output\OutputInterface;
1616
use Symfony\Component\Console\Style\SymfonyStyle;
17-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
17+
use Symfony\Component\DependencyInjection\ContainerInterface;
1818

1919
final class ExportDataCommand extends Command
2020
{
21-
use ContainerAwareTrait;
22-
2321
/** @var ExporterRegistry */
2422
private $exporterRegistry;
23+
/** @var ContainerInterface */
24+
private $container;
2525

2626
public function __construct(ExporterRegistry $exporterRegistry)
2727
{
@@ -30,6 +30,11 @@ public function __construct(ExporterRegistry $exporterRegistry)
3030
parent::__construct();
3131
}
3232

33+
public function setContainer(ContainerInterface $container): void
34+
{
35+
$this->container = $container;
36+
}
37+
3338
/**
3439
* {@inheritdoc}
3540
*/

src/Command/ExportDataToMessageQueueCommand.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
use Symfony\Component\Console\Input\InputInterface;
1515
use Symfony\Component\Console\Output\OutputInterface;
1616
use Symfony\Component\Console\Style\SymfonyStyle;
17-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
17+
use Symfony\Component\DependencyInjection\ContainerInterface;
1818

1919
final class ExportDataToMessageQueueCommand extends Command
2020
{
21-
use ContainerAwareTrait;
22-
2321
/** @var ExporterRegistry */
2422
private $exporterRegistry;
23+
/** @var ContainerInterface */
24+
private $container;
2525

2626
public function __construct(ExporterRegistry $exporterRegistry)
2727
{
@@ -30,6 +30,11 @@ public function __construct(ExporterRegistry $exporterRegistry)
3030
parent::__construct();
3131
}
3232

33+
public function setContainer(ContainerInterface $container): void
34+
{
35+
$this->container = $container;
36+
}
37+
3338
/**
3439
* {@inheritdoc}
3540
*/
@@ -46,15 +51,15 @@ protected function configure(): void
4651
/**
4752
* {@inheritdoc}
4853
*/
49-
protected function execute(InputInterface $input, OutputInterface $output): void
54+
protected function execute(InputInterface $input, OutputInterface $output): int
5055
{
5156
/** @var string $exporter */
5257
$exporter = $input->getArgument('exporter');
5358

5459
if (empty($exporter)) {
5560
$this->listExporters($input, $output);
5661

57-
return;
62+
return 0;
5863
}
5964

6065
$domain = 'sylius';
@@ -82,6 +87,8 @@ protected function execute(InputInterface $input, OutputInterface $output): void
8287
$mqItemWriter = $this->container->get('sylius.message_queue_writer');
8388
$this->export($mqItemWriter, $name, $idsToExport, $exporter);
8489
$this->finishExport($items, 'message queue', $name, $output);
90+
91+
return 0;
8592
}
8693

8794
private function listExporters(InputInterface $input, OutputInterface $output, ?string $errorMessage = null): void

src/Command/ImportDataFromMessageQueueCommand.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
use Symfony\Component\Console\Input\InputOption;
1414
use Symfony\Component\Console\Output\OutputInterface;
1515
use Symfony\Component\Console\Style\SymfonyStyle;
16-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
16+
use Symfony\Component\DependencyInjection\ContainerInterface;
1717

1818
final class ImportDataFromMessageQueueCommand extends Command
1919
{
20-
use ContainerAwareTrait;
21-
2220
/** @var ImporterRegistry */
2321
private $importerRegistry;
22+
/** @var ContainerInterface */
23+
private $container;
2424

2525
public function __construct(ImporterRegistry $importerRegistry)
2626
{
@@ -29,6 +29,11 @@ public function __construct(ImporterRegistry $importerRegistry)
2929
parent::__construct();
3030
}
3131

32+
public function setContainer(ContainerInterface $container): void
33+
{
34+
$this->container = $container;
35+
}
36+
3237
/**
3338
* {@inheritdoc}
3439
*/

src/DependencyInjection/Compiler/RegisterImporterPass.php

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@
55
namespace FriendsOfSylius\SyliusImportExportPlugin\DependencyInjection\Compiler;
66

77
use FriendsOfSylius\SyliusImportExportPlugin\Importer\ImporterRegistry;
8-
use Sylius\Bundle\UiBundle\Block\BlockEventListener;
8+
use Sylius\TwigHooks\Hookable\HookableTemplate;
99
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1010
use Symfony\Component\DependencyInjection\ContainerBuilder;
1111
use Symfony\Component\DependencyInjection\Reference;
1212

1313
final class RegisterImporterPass implements CompilerPassInterface
1414
{
15-
private $eventHookNames = [
16-
'taxonomy' => 'app.block_event_listener.admin.taxon.create.after_content',
17-
];
18-
19-
private $eventNames = [
20-
'taxonomy' => 'sonata.block.event.sylius.admin.taxon.create.after_content',
15+
private $twigHookNames = [
16+
'taxonomy' => 'sylius_admin.taxon.create.content.sections#right',
2117
];
2218

2319
private $templateNames = [
@@ -59,57 +55,37 @@ public function process(ContainerBuilder $container): void
5955

6056
private function registerImportFormBlockEvent(ContainerBuilder $container, string $type, ?string $domain): void
6157
{
62-
$eventHookName = $this->buildEventHookName($type);
58+
$twigHookName = $this->buildTwigHookName($type);
59+
$twigHookId = sprintf('%s.%s', $twigHookName, $type);
6360

64-
if ($container->has($eventHookName)) {
61+
if ($container->has($twigHookId)) {
6562
return;
6663
}
6764

68-
$eventName = $this->buildEventName($type, $domain);
6965
$templateName = $this->buildTemplateName($type);
66+
7067
$container
71-
->register(
72-
$eventHookName,
73-
BlockEventListener::class
74-
)
75-
->setAutowired(false)
76-
->addArgument($templateName)
77-
->addTag(
78-
'kernel.event_listener',
79-
[
80-
'event' => $eventName,
81-
'method' => 'onBlockEvent',
82-
]
83-
)
68+
->register($twigHookId, HookableTemplate::class)
69+
->setArguments([
70+
$twigHookName,
71+
$type,
72+
$templateName,
73+
[],
74+
['resource' => $type],
75+
null,
76+
true,
77+
])
78+
->addTag('sylius_twig_hooks.hookable', ['priority' => 0])
8479
;
8580
}
8681

87-
private function buildEventHookName(string $type): string
88-
{
89-
if (isset($this->eventHookNames[$type])) {
90-
return $this->eventHookNames[$type];
91-
}
92-
93-
return sprintf('app.block_event_listener.admin.crud.after_content_%s.import', $type);
94-
}
95-
96-
private function buildEventName(string $type, ?string $domain): string
82+
private function buildTwigHookName(string $type): string
9783
{
98-
if (isset($this->eventNames[$type])) {
99-
return $this->eventNames[$type];
100-
}
101-
102-
$domain = $domain ?? 'sylius';
103-
// backward compatibility with the old configuration
104-
if (count(\explode('.', $type)) === 2) {
105-
[$domain, $type] = \explode('.', $type);
84+
if (isset($this->twigHookNames[$type])) {
85+
return $this->twigHookNames[$type];
10686
}
10787

108-
return \sprintf(
109-
'sonata.block.event.%s.admin.%s.index.after_content',
110-
$domain,
111-
$type
112-
);
88+
return sprintf('sylius_admin.%s.index.content.grid', $type);
11389
}
11490

11591
private function buildTemplateName(string $type): string

src/Listener/ExportButtonGridListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function onSyliusGridAdmin(GridDefinitionConverterEvent $event): void
5252
$action->setLabel('fos.import_export.ui.export');
5353
$action->setOptions([
5454
'class' => '',
55-
'icon' => 'save',
55+
'icon' => 'tabler:download',
5656
'header' => [
5757
'icon' => 'file code outline',
5858
'label' => 'sylius.ui.type',
@@ -98,7 +98,7 @@ private function addLink(string $format): array
9898

9999
return [
100100
'label' => 'fos.import_export.ui.types.' . $format,
101-
'icon' => 'file archive',
101+
'icon' => 'tabler:file-download',
102102
'route' => \sprintf('app_export_data_%s', $resource),
103103
'parameters' => $parameters,
104104
];

src/Resources/config/services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,6 @@ services:
368368
arguments:
369369
- "@sylius.custom_factory.taxon"
370370
- "@sylius.repository.taxon"
371-
- "@sylius.locale_provider"
371+
- "@sylius.provider.locale"
372372
- "@sylius.importer.metadata_validator"
373373
- ["Code", "Parent", "Locale", "Name", "Slug", "Description"]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{{ render(controller(
22
'sylius.controller.import_data::importFormAction',
3-
{'resource': block.settings.resources.metadata.name}
3+
{'resource': hookable_metadata.configuration.resource}
44
)) }}
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
{% form_theme form '@FOSSyliusImportExportPlugin/Form/theme.html.twig' %}
1+
{% form_theme form '@SyliusAdmin/shared/form_theme.html.twig' %}
22
{% set header = 'sylius.ui.'~resource %}
33

4-
<div class="ui styled fluid accordion">
5-
<div class="title active">
6-
<i class="dropdown icon"></i>
7-
{{ 'fos.import_export.ui.import'|trans }} {{ header|trans }}
8-
</div>
9-
<div class="content active">
10-
{{ form_start(form, {
11-
'action': path('app_import_data', {'resource': resource}),
12-
'method': 'POST',
13-
'attr': {'class': 'ui loadable form', 'novalidate': 'novalidate'}
14-
}) }}
15-
<div class="ui segment">
16-
{{ form_widget(form) }}
4+
<div class="card">
5+
<div class="card-body">
6+
<h5 class="card-title">{{ 'fos.import_export.ui.import'|trans }} {{ header|trans }}</h5>
7+
<div class="card-text">
8+
{{ form_start(form, {
9+
'action': path('app_import_data', {'resource': resource}),
10+
'method': 'POST',
11+
'attr': {'novalidate': 'novalidate'}
12+
}) }}
13+
<div class="row">
14+
{{ form_widget(form) }}
15+
</div>
16+
17+
<button type="submit" class="btn">
18+
{{ resource|capitalize }} {{ 'fos.import_export.ui.import'|trans }}
19+
</button>
20+
{{ form_end(form) }}
1721
</div>
18-
<button class="ui icon primary button" type="submit" id="import-data">
19-
{{ resource|capitalize }} {{ 'fos.import_export.ui.import'|trans }}
20-
</button>
21-
{{ form_end(form) }}
2222
</div>
2323
</div>

src/Resources/views/Form/theme.html.twig

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)