From 9b4bf2a09962a4cfb8f7e8411e6ba4ceaf3d7153 Mon Sep 17 00:00:00 2001 From: Catalin G Date: Tue, 23 Nov 2021 17:30:23 +0200 Subject: [PATCH] Added option to use 'domain' in service config tag so instead of type taking the value "app.foo" you will use "type: foo" and "domain: app" This fixes the selection of export format in the admin interface. --- README.md | 6 +++--- .../Compiler/RegisterImporterPass.php | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6005ae79..4780da86 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ admin overview panel using the event hook system, ie. `admin/tax-categories/`. #### Notes - - Replace `app.foo` with the name of the resource (under `sylius_resource` config) you want to implement in the following examples. + - Replace `app` and `foo` with the name of the resource (under `sylius_resource` config) you want to implement in the following examples. - Replace `bar` with the name of the format you want to implement in the following examples (csv, json, ...). - Note it is of course also possible to implement a dedicated importer for `app.foo` resource and format `bar`, in case a generic type implementation is not possible. @@ -177,7 +177,7 @@ sylius.importer.foo.bar: - "@sylius.processor.foo" - "@sylius.importer.result" tags: - - { name: sylius.importer, type: app.foo, format: csv } + - { name: sylius.importer, type: foo, domain: app, format: csv } ``` ##### Alternatively implement a custom ResourceImporter _FooImporter_ @@ -199,7 +199,7 @@ sylius.importer.foo.bar: - "@sylius.processor.foo" - "@sylius.importer.result" tags: - - { name: sylius.importer, type: app.foo, format: bar } + - { name: sylius.importer, type: foo, domain: app, format: bar } ``` #### Adding a ResourceProcessor diff --git a/src/DependencyInjection/Compiler/RegisterImporterPass.php b/src/DependencyInjection/Compiler/RegisterImporterPass.php index 7a36552f..0ef90554 100644 --- a/src/DependencyInjection/Compiler/RegisterImporterPass.php +++ b/src/DependencyInjection/Compiler/RegisterImporterPass.php @@ -46,17 +46,18 @@ public function process(ContainerBuilder $container): void $type = $attributes[0]['type']; $format = $attributes[0]['format']; + $domain = $attributes[0]['domain'] ?? null; $name = ImporterRegistry::buildServiceName($type, $format); $importersRegistry->addMethodCall('register', [$name, new Reference($id)]); if ($container->getParameter('sylius.importer.web_ui')) { - $this->registerImportFormBlockEvent($container, $type); + $this->registerImportFormBlockEvent($container, $type, $domain); } } } - private function registerImportFormBlockEvent(ContainerBuilder $container, string $type): void + private function registerImportFormBlockEvent(ContainerBuilder $container, string $type, ?string $domain): void { $eventHookName = $this->buildEventHookName($type); @@ -64,7 +65,7 @@ private function registerImportFormBlockEvent(ContainerBuilder $container, strin return; } - $eventName = $this->buildEventName($type); + $eventName = $this->buildEventName($type, $domain); $templateName = $this->buildTemplateName($type); $container ->register( @@ -92,13 +93,13 @@ private function buildEventHookName(string $type): string return sprintf('app.block_event_listener.admin.crud.after_content_%s.import', $type); } - private function buildEventName(string $type): string + private function buildEventName(string $type, ?string $domain): string { if (isset($this->eventNames[$type])) { return $this->eventNames[$type]; } - $domain = 'sylius'; + $domain = $domain ?? 'sylius'; // backward compatibility with the old configuration if (count(\explode('.', $type)) === 2) { [$domain, $type] = \explode('.', $type);